Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ada-Europe 2002 Ada, Interfaces, and the Listener Paradigm J-P. Rosen Adalog An AXLOG Group company

Similar presentations


Presentation on theme: "Ada-Europe 2002 Ada, Interfaces, and the Listener Paradigm J-P. Rosen Adalog An AXLOG Group company"— Presentation transcript:

1 Ada-Europe 2002 Ada, Interfaces, and the Listener Paradigm J-P. Rosen Adalog An AXLOG Group company rosen@adalog.fr

2 Ada-Europe 2002 Two views of inheritance The "delta programming" approach Parent_Class Method_1 Method_2 Derived_Class Method_1 Method_2 Redefined The "default behavior" approach

3 Ada-Europe 2002 Interfaces in Java No inheritance of implementation +In a sense, the opposite of inheritance +Not necessarily an "is a" relationship An_Interface Method_1 Method_2 Another_Class Method_1 Method_2 A_Class Method_1 Method_2 Implements A promised interface

4 Ada-Europe 2002 Inner classes A class defined inside another class An instance of an inner class is linked to an instance of the outer class A_ClassInner_Class Method_1 Method_2

5 Ada-Europe 2002 Interfaces vs. Inner Classes An interface has direct visibility on all fields of the class +An inner class has access to all elements of its enclosing object. It is possible to have a linked list of various objects implementing a given interface +Inner objects can be linked also They are functionally equivalent

6 Ada-Europe 2002 The building-block approach

7 Ada-Europe 2002 The building-block approach

8 Ada-Europe 2002 package Wakeable_Interface is type Instance is abstract tagged limited null record; type Handle is access all Instance'Class; procedure Every_Second (This : access Instance) is abstract; end Wakeable_Interface; A design pattern for interfaces in Ada generic type Ancestor is tagged limited private; with procedure Every_Second (Item : access Ancestor) is <>; package Implements_Wakeable is type Instance is new Ancestor with private; type Handle is access all Instance'Class; function Wakeable_Of (Item : access Instance) return Wakeable_Interface.Handle; function Full_Object_Of (Item : Wakeable_Interface.Handle) return Handle; private... end Implements_Wakeable;

9 Ada-Europe 2002 Using the Design Pattern package Data1 is type Instance is tagged limited private; type Handle is access all Instance'Class; procedure Init (Item : access Instance; Value : Integer); procedure Processing (Item : access Instance); procedure Every_Second (Item : access Instance); private type Instance is tagged limited record Value : Integer; end record; end Data1; with Wakeable_Interface; use Wakeable_Interface; package Data1.Wakeable is new Implements_Wakeable (Data1.Instance, Processing); with Wakeable_Interface; use Wakeable_Interface; package Data1.Wakeable is new Implements_Wakeable (Data1.Instance); Every_Second selected automatically Use another procedure for the interface

10 Ada-Europe 2002 Using the Design Pattern with Data1.Wakeable, Wakeable_Interface; procedure Example is use Data1, Data1.Wakeable, Wakeable_Interface; Handle_1 : Data1.Wakeable.Handle; Handle_2 : Wakeable_Interface.Handle; begin Handle_1 := new Data1.Wakeable.Instance; Init (Handle_1, 5); Handle_2 := Wakeable_Of (H1); Every_Second (Handle_2); Processing (Full_Object_Of (Handle_2)); end Example; Using the object through the interface Object creation Going from interface to full object

11 Ada-Europe 2002 What are interfaces used for in Java? Flags +No kidding! Simple interfaces +Serializable, Comparable... (Restricted) multiple inheritance +If the interface corresponds to a "is a" relationship Listeners +When objects take actions in response to events. +Objects must register to a notifier. +Basically, a concurrent behavior.

12 Ada-Europe 2002 Various implementations of the listener paradigm Call-backs Extended call-backs: Interfaces +Register a pointer to an interface to avoid registering multiple pointers to subprograms. A_Class Method_1 Method_2 Notifier Register Procedure pointer Ada has pointers to subprograms Previous design pattern is OK

13 Ada-Europe 2002 Formal_Call Various implementations of the listener paradigm Generics A_Class Method_1 Method_2 Notifier OK in Ada, not an option in Java

14 Ada-Europe 2002 Various implementations of the listener paradigm Tasking / Polling Tasking / Entries Server Get_Event ClientServer Get_Event Client

15 Ada-Europe 2002 Comparison IdiomActive?Registration Multiple listeners Multiple events Call-backNoExplicitYesNo InterfaceNoExplicitYes GenericNoStaticNoYes Task, PollingYes, not blockingAutomaticNoYes Task, EntryYes, blockingAutomaticYesNo No absolute winner!

16 Ada-Europe 2002 The Ada0Y proposal ! Work in Progress type Stack is abstract; --... Operations on Stack type Queue is abstract; --... Operations on Queue An abstract interface type Another interface type Deque is abstract new Queue and Stack; --... Operations on Deque An interface which inherits from both the Queue and Stack interfaces. type My_Deque is new Blob and Deque with record -- Conventional type implementing an interface.... end record; An extension that implements an interface

17 Ada-Europe 2002 Conclusion Interfaces are an interesting concept +They bring convenience There is no technical necessity +Current building blocks provide the service They are less important in Ada than in Java +Ada has more tools The necessity of interfaces in Ada should not be overestimated

18 Ada-Europe 2002?Questions


Download ppt "Ada-Europe 2002 Ada, Interfaces, and the Listener Paradigm J-P. Rosen Adalog An AXLOG Group company"

Similar presentations


Ads by Google