Chair of Software Engineering ATOT - Lecture 20, 11 June 2003 1 Advanced Topics in Object Technology Bertrand Meyer.

Slides:



Advertisements
Similar presentations
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Advertisements

Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 10: Advanced Object-Oriented Mechanisms (based on.
1 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 13.
2 nd Microsoft Rotor Workshop, Pisa, April 23-25, SCOOPLI for.NET: a library for concurrent object-oriented programming Volkan Arslan, Piotr Nienaltowski.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session November 2008.
Event-Driven programming, agents & tuples.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
Chair of Software Engineering ATOT - Lecture 25, 30 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 8: More on inheritance.
Chair of Software Engineering ATOT - Lecture 24, 25 June Advanced Topics in Object Technology Bertrand Meyer.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Chair of Software Engineering ATOT - Lecture 17, 28 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 10: Project Presentation Ilinca.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering ATOT - Lecture 8, 28 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer.
Event-Driven programming, agents & tuples.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Lecture #4 Agenda Announcements Review Questions? Classes and objects UML class diagrams Creating.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 17: Event-driven programming.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Chair of Software Engineering OOSC - Lecture 21 1 Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 25, 30 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering 1 Introduction to Programming Tuples and Agents Exercise Session 1 and 2 December 2008.
Chair of Software Engineering ATOT - Lecture 11, 7 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 23, 23 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 2, 2 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
Chair of Software Engineering ATOT - Lecture 3, 7 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Software Architecture Prof. Dr. Bertrand Meyer Lecture 7: Patterns, Observer, MVC.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Chair of Software Engineering OOSC - Summer Semester Object Oriented Software Construction Prof. Dr. Bertrand Meyer Last update: 7 May 2005 Lecture.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 15: Event-driven programming.
Chair of Software Engineering Object-Oriented Software Construction Bertrand Meyer Lecture 21: Agents and tuples.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering ATOT - Lecture 7, 23 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 11.
Chair of Software Engineering ATOT - Lecture 22, 18 June Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering JMLC 2003, , Klagenfurt Austria Event Library: an object-oriented library for event-driven design Volkan Arslan,
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Ranga Rodrigo. Class is central to object oriented programming.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
10 Conversion. Let’s start with conformance Conformance determines when a type may be used in lieu of another. Conformance relies on inheritance. The.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Introduction to Object-Oriented Programming Lesson 2.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Fall 2013 Chapter 10 Thinking.
Object Oriented Programming in Java Habib Rostami Lecture 2.
Chapter 10 Thinking in Objects
Chapter 10 Thinking in Objects
Chapter 10 Thinking in Objects
Chapter 9 Thinking in Objects
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Delegates & Events 1.
Chapter 9 Thinking in Objects
Events, Delegates, and Lambdas
Presentation transcript:

Chair of Software Engineering ATOT - Lecture 20, 11 June Advanced Topics in Object Technology Bertrand Meyer

Chair of Software Engineering ATOT - Lecture 20, 11 June Lecture 20: Agents and event-driven design

Chair of Software Engineering ATOT - Lecture 20, 11 June Agenda for today  Scope of this development  Applications  The mechanism

Chair of Software Engineering ATOT - Lecture 20, 11 June Dogmatism Processor ObjectAction

Chair of Software Engineering ATOT - Lecture 20, 11 June Agenda for today  Scope of this development  Applications  The mechanism

Chair of Software Engineering ATOT - Lecture 20, 11 June Scope  Starting from an object-oriented basis, add a new kind of objects representing potential computations.  Such objects are called “agents”.  Earlier names:  Delayed calls  Routine objects  Similar to:  “Closures”  Delegates (C#)  Blocks (Smalltalk)  Lambda expressions

Chair of Software Engineering ATOT - Lecture 20, 11 June Compare to… ... “Functional” style of programming, e.g. Haskell  Conjecture: Haskell should be an Eiffel library (Eifskell?)

Chair of Software Engineering ATOT - Lecture 20, 11 June Extensions (Eiffel: The Language, 1991)  “There is one and only one kind of acceptable language extension: the one that dawns on you with the sudden self-evidence of morning mist. It must provide a complete solution to a real problem, but usually that is not enough: almost all good extensions solve several potential problems at once, through a simple addition. It must be simple, elegant, explainable to any competent user of the language in a minute or two. It must fit perfectly within the spirit and letter of the rest of the language. It must not have any dark sides or raise any unanswerable questions. And because software engineering is engineering, you must see the implementation technique.”

Chair of Software Engineering ATOT - Lecture 20, 11 June The starting idea of object-technology  Organize software architecture around data types.  Agents: Can an object represent an action? Processor ObjectAction

Chair of Software Engineering ATOT - Lecture 20, 11 June Agenda for today  Scope of this development  Applications  The mechanism

Chair of Software Engineering ATOT - Lecture 20, 11 June Applications of agents  Iteration  High-level contracts  Numerical programming  Introspection  High-level functionals, type-safe

Chair of Software Engineering ATOT - Lecture 20, 11 June Integration example (1) b  my_function (x) dx a my_integrator.integral (agent my_function, a, b)

Chair of Software Engineering ATOT - Lecture 20, 11 June b  your_function (x, u, v) dx a my_integrator.integral (agent your_function (?, u, v), a, b)  In the first example (one argument), the notation agent my_function  is a synonym for agent my_function (?) Integration example (2)

Chair of Software Engineering ATOT - Lecture 20, 11 June Agenda for today  Scope of this development  Applications  The mechanism

Chair of Software Engineering ATOT - Lecture 20, 11 June Open and closed arguments agent your_function (?, u, v)  Closed: set at the time of the agent’s definition  Open: set at the time of any call to the agent Closed Open

Chair of Software Engineering ATOT - Lecture 20, 11 June Using a routine from another class agent some_object.some_routine (?, u, v) Target

Chair of Software Engineering ATOT - Lecture 20, 11 June Iteration  Consider my_integer_list: LIST [INTEGER]  in a class C that has the function is_positive (x: INTEGER): BOOLEAN is -- Is x positive? do Result := (x > 0) end  To test that all integers in a list are positive: all_positive := my_integer_list.for_all (agent is_positive)

Chair of Software Engineering ATOT - Lecture 20, 11 June Iteration (cont’d)  Consider my_employee_list: LIST [EMPLOYEE]  where class EMPLOYEE has the feature is_married: BOOLEAN -- Does this object represent a -- married employee?  To test that all employees in a list are married: all_married := my_employee_list.for_all (agent {EMPLOYEE}.is_married)

Chair of Software Engineering ATOT - Lecture 20, 11 June Target or argument open  Compare the two examples (both in a class C): my_integer_list: LIST [INTEGER] my_employee_list: LIST [EMPLOYEE] is_positive (x: INTEGER): BOOLEAN-- In class C is_married: BOOLEAN-- In class EMPLOYEE -- Abbreviated as -- my_integer_list.for_all (agent is_positive): my_integer_list.for_all (agent is_positive (?)) my_employee_list.for_all (agent {EMPLOYEE}.is_married) Open

Chair of Software Engineering ATOT - Lecture 20, 11 June An EiffelBase contract (class HASH_TABLE) extend (new: G; key: H) -- Assuming there is no item of key key, -- insert new with key; set inserted. require not_key_present: not has (key) ensure insertion_done: item (key) = new key_present: has (key) inserted: inserted one_more: count = old count + 1

Chair of Software Engineering ATOT - Lecture 20, 11 June Agents’ potential for contracts  Express general properties such as “none of the elements from positions 1 to count – 1 have been changed”.

Chair of Software Engineering ATOT - Lecture 20, 11 June Event-driven programming PUBLISHERSSUBSCRIBERS trigger eventshandle events EVENTS ROUTINE

Chair of Software Engineering ATOT - Lecture 20, 11 June Event Library  Class EVENT_TYPE  Publisher side, e.g. GUI library:  (Once) declare event type: click: EVENT_TYPE [TUPLE [INTEGER, INTEGER]]  (Once) create event type object: create click  Each time the event occurs: click.publish ([x_coordinate, y_coordinate])  Subscriber side: click.subscribe (agent my_procedure)

Chair of Software Engineering ATOT - Lecture 20, 11 June Subscriber variants click.subscribe (agent my_procedure) my_button.click.subscribe (agent my_procedure) click.subscribe (agent your_procedure (a, ?, ?, b)) click.subscribe (agent other_object.other_procedure)

Chair of Software Engineering ATOT - Lecture 20, 11 June EiffelVision style my_button.click.action_list.extend (agent my_procedure)

Chair of Software Engineering ATOT - Lecture 20, 11 June Observer pattern (C++, Java) SUBSCRIBER * PUBLISHER * APPCLASS LIBCLASS attach detach update* update+ Deferred (abstract) Effective (implemented) * + Inherits from Client (uses)

Chair of Software Engineering ATOT - Lecture 20, 11 June Observer pattern  Publishers know about subscribers  Subscriber may subscribe to at most one publisher  May subscribe at most one operation  Not reusable — must be coded anew for each application

Chair of Software Engineering ATOT - Lecture 20, 11 June Event library  Publisher, e.g. GUI library:  Declare and create: click: EVENT_TYPE [TUPLE [INTEGER, INTEGER]]  Trigger each event with arguments. click.publish ([x, y])  Subscriber (to subscribe a routine r): my_button.click.subscribe (agent r)

Chair of Software Engineering ATOT - Lecture 20, 11 June NET event-delegate mechanism  Publisher or subscriber:  Introduce descendant ClickArgs of EventArgs repeating types of arguments of myProcedure. (Adds a class.) public class ClickArgs { int x, y;... }  Declare delegate type ClickDelegate based on that class. (Adds a type.) public void delegate ClickDelegate (Object sender, ClickArgs e); D1 D2

Chair of Software Engineering ATOT - Lecture 20, 11 June  Declare new event type Click based on the type ClickDelegate. (Adds a type.) public event ClickDelegate Click;  Write procedure OnClick to wrap handling. (Adds a routine.) protected void OnClick (ClickArgs e) { if (Click != null) Click (this, e); }  For every event occurrence, create instance of ClickArgs, passing arg values to constructor. (Adds a run-time object.) ClickArgs myClickArgs = new ClickArgs (h, v);  For every occurrence, trigger event OnClick (myClickArgs);.NET delegates (2): publisher D3 D4 D5 D6

Chair of Software Engineering ATOT - Lecture 20, 11 June NET delegates (3): subscriber  To subscribe a routine myProcedure:  Declare a delegate myDelegate of type ClickDelegate. (Can be combined with following step as shown next.)  Instantiate it with myProcedure as constructor’s argument. ClickDelegate myDelegate = new ClickDelegate (myProcedure)  Add it to the delegate list for the event. yourButton.Click += myDelegate D7 D8 D9

Chair of Software Engineering ATOT - Lecture 20, 11 June NET delegates (4)  event is a keyword of the language (special features of a class). But event types should be treated as ordinary objects.  Cannot have closed arguments: for equivalent of r (a, ?, ?, b) must write routine wrapper to be used for delegate.  Cannot have open target: for equivalent of {TYPE}.r (...) must write routine wrapper.

Chair of Software Engineering ATOT - Lecture 20, 11 June Lessons  Avoid magic: what’s available to the language designer should be available to the programmer  Role of language mechanisms: genericity, constrained genericity, tuples  Importance of choosing the right abstractions  Observer Pattern: PUBLISHER, SUBSCRIBER .NET: event, delegate, event type, delegate type?  Eiffel Event Library: EVENT_TYPE

Chair of Software Engineering ATOT - Lecture 20, 11 June Observer pattern (C++, Java) SUBSCRIBER * PUBLISHER * APPCLASS LIBCLASS attach detach update* update+ Deferred (abstract) Effective (implemented) * + Inherits from Client (uses)

Chair of Software Engineering ATOT - Lecture 20, 11 June End of lecture 20