Download presentation
Presentation is loading. Please wait.
Published byCecilia Washington Modified over 9 years ago
1
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Event Library: an object-oriented library for event-driven design Volkan Arslan, Piotr Nienaltowski, Karine Arnout Chair of Software Engineering, ETH Zurich, Switzerland http://se.inf.ethz.ch http://se.inf.ethz.ch {Volkan.Arslan, Piotr.Nienaltowski, Karine.Arnout}@inf.ethz.ch
2
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Overview Motivation Use of the Event Library Example: Event Library in action Architecture of the Event Library Conclusion and future work
3
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Event-driven programming Event-driven programming is very popular, especially for GUI applications Facilitates the separation of concerns: application layer and GUI Publish/Subscribe and Observer pattern follow the event-driven approach
4
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Event Library Make things as simple as possible, but not simpler. (A. Einstein) Turn the Observer pattern to a simple, reusable, but powerful library Event Library
5
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Use of the Event Library Using the Event Library consists only of 3 steps: 1.PUBLISHER defines an event type 2.SUBSCRIBER subscribes a feature of an object to an event type 3.PUBLISHER publishes an event (of a certain event type)
6
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Example: Event Library in action
7
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Class SENSOR class SENSOR feature -- Access temperature: INTEGER -- Container temperature humidity: INTEGER -- Container humidity pressure: INTEGER -- Container pressure end -- class SENSOR
8
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Class SENSOR class SENSOR feature -- Access temperature: INTEGER -- Container temperature feature -- Element change set_temperature (a_temperature: INTEGER) is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature := a_temperature ensure temperature_set: temperature = a_temperature end end -- class SENSOR
9
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria (1) Publisher defines an event type class SENSOR feature -- Access temperature: INTEGER -- Container temperature feature -- Element change set_temperature (a_temperature: INTEGER) is -- Set temperature to a_temperature.... feature -- Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] -- Event associated with attribute temperature. invariant temperature_event_not_void: temperature_event /= Void end -- class SENSOR EVENT_TYPE [EVENT_DATA -> TUPLE] [40, 60] [25] [] conforms to
10
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria (2) Subscription to an event type In subscriber class MAIN_WINDOW Sensor.temperature_event.subscribe (agent application_window_1.display_temperature (?)) In the subscribed class APPLICATION_WINDOW display_temperature (a_temperature: INTEGER) is -- Update the text of temperature_value_label -- with a_temperature. do … end
11
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria (2) Subscription to an event type In class MAIN_WINDOW (Subscriber) Sensor.temperature_event.subscribe (agent application_window_1.display_temperature (?)) Class EVENT_TYPE subscribe (an_action: PROCEDURE [ANY, EVENT_DATA]) is -- Add an_action to the subscription list. require an_action_not_void: an_action /= Void an_action_not_already_subscribed: not has (an_action) ensure an_action_subscribed: count = old count + 1 and has (an_action) EVENT_TYPE [EVENT_DATA -> TUPLE]
12
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria (3) Publisher publishes an event class SENSOR feature -- Access temperature: INTEGER -- Container temperature feature -- Element change set_temperature (a_temperature: INTEGER) is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature := a_temperature temperature_event.publish ([temperature]) ensure temperature_set: temperature = a_temperature end feature – Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] end -- class SENSOR
13
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria (3) Publisher publishes an event class SENSOR … feature -- Element change set_temperature (a_temperature: INTEGER) is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature := a_temperature temperature_event.publish ([temperature]) ensure temperature_set: temperature = a_temperature end feature – Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] end -- class SENSOR Class EVENT_TYPE publish (arguments: EVENT_DATA) is -- Publish all not suspended actions from the subscription list. require arguments_not_void: arguments /= Void EVENT_TYPE [EVENT_DATA -> TUPLE]
14
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria (3) Publisher publishes an event class SENSOR … feature -- Element change set_temperature (a_temperature: INTEGER) is -- Set temperature to a_temperature. require valid_temperature: a_temperature > -100 and a_temperature < 1000 do temperature := a_temperature temperature_event.publish ([temperature]) ensure temperature_set: temperature = a_temperature end feature – Events temperature_event: EVENT_TYPE [TUPLE [INTEGER]] end -- class SENSOR Class EVENT_TYPE publish (arguments: EVENT_DATA) is -- Publish all not suspended actions from the subscription list. do do_all (agent {PROCEDURE [ANY, EVENT_DATA]}.call (arguments)) end EVENT_TYPE [EVENT_DATA -> TUPLE]
15
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Architecture Classification according to Eugster P. Th. [3] Space decoupling The publisher and the subscribed class do not know each other Flow decoupling Publishers should be not blocked, while publishing events Time decoupling Publishers and subscribed objects do not have to participate actively in the interaction at the same time (e.g. distributed setting)
16
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Conclusion Event Library is simple to use Consists of only one class EVENT_TYPE Publisher, Subscriber and Subscribed object Supports full event-driven programming Type safe For advanced needs, class EVENT_TYPE is extendible It relies on powerful language mechanism Genericity (including constrained genericity) Tuples Agents Inheritance
17
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Future work Extension of the Event Library “Conditional Event subscription” possible when inline agents are introduced to the language Use of concurrency (SCOOP) in order to obtain flow and time decoupling Guaranteeing response times for subscribed objects when an event of a certain event type is triggered. General publish-subscribe mechanism available as Web Service (time decoupling)
18
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria References 1.Arslan V.: Event Library, at http://se.inf.ethz.ch/people/arslanhttp://se.inf.ethz.ch/people/arslan 2.Eiffel Software Inc.: Agents, iteration and introspection, at http://archive.eiffel.com/doc/manuals/language/agent/agent.pdf http://archive.eiffel.com/doc/manuals/language/agent/agent.pdf 3.Eugster P. Th., Felber P., Guerraoui R., Kermarrec A.-M.: The Many Faces of Publish/Subscribe, Technical Report 200104 at http://icwww.epfl.ch/publications/documents/IC_TECH_REPORT_200104.p df http://icwww.epfl.ch/publications/documents/IC_TECH_REPORT_200104.p df 4.Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns: Elements of Reusable Object-Oriented Software, 1st edition, Addison-Wesley, 1995. 5.Meyer B.: The power of abstraction, reuse and simplicity: an object- oriented library for event-driven design, at http://www.inf.ethz.ch/~meyer/ongoing/events.pdf. http://www.inf.ethz.ch/~meyer/ongoing/events.pdf 6.Nienaltowski P., Arslan V.: SCOOPLI: a library for concurrent object- oriented programming on.NET, in Proceedings of the 1st International Workshop on C# and.NET Technologies, University of West Bohemia, 5-8 February 2003, Pilsen, Czech Republic.
19
Chair of Software Engineering JMLC 2003, 26.08.2003, Klagenfurt Austria Questions ? Thank you for your attention!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.