1 / 50

Beyond 2000, Beyond Object-Orientation

Beyond 2000, Beyond Object-Orientation. László Kozma <kozma@ludens.elte.hu> Ákos Frohner <szamcsi@elte.hu> Tamás Kozsik <kto@elte.hu> Zoltán Porkoláb <gsd@elte.hu>. Introduction. Paradigms Object-orientation Generic programming Aspect-oriented programming Functional programming

emilie
Télécharger la présentation

Beyond 2000, Beyond Object-Orientation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Beyond 2000, Beyond Object-Orientation László Kozma <kozma@ludens.elte.hu> Ákos Frohner <szamcsi@elte.hu> Tamás Kozsik <kto@elte.hu> Zoltán Porkoláb <gsd@elte.hu>

  2. Introduction • Paradigms • Object-orientation • Generic programming • Aspect-oriented programming • Functional programming • Component-oriented software technology • Conclusion Beyond 2k Beyond OO

  3. Object-Orientation • Object • Class • data structure • operation • role • Inheritance hierarchy • Polymorphism (inclusion) Beyond 2k Beyond OO

  4. GP - Example (1) • class intStack { • public: • void push(int); • int pop(); • }; • class ptrStack { • public: • void push(char*); • char* pop(); • }; class stack { public: virtual void push( ? ); virtual ? pop(); // ... private: int capacity; int stack_ptr; ? *elems; // ... }; Beyond 2k Beyond OO

  5. GP - Example (2) template <typename T> class stack { public: virtual void push( T ); virtual T pop(); // ... private: int capacity; int stack_ptr; T *elems; // ... }; Beyond 2k Beyond OO

  6. Generic Programming • Compile-time type checking • Automatic instantiation • Efficient ( vs. Reflection ) • Simple • Negative variance: template specialisation • (Parametric) Polymorphism Beyond 2k Beyond OO

  7. GP - Standard Template Library • A. Stepanov, D. Musser • ADA, C++, JAVA (Pizza, GJ, Collection) • C++ Standard Template Library • containers • algorithms • iterators • Part of the ISO C++ standard (1997) Beyond 2k Beyond OO

  8. Standard Template Library Find Iterator Vector Merge Iterator Iterator List Beyond 2k Beyond OO

  9. GP - Coexistence with OO • C++ Standard Library (!= STL) • Reduce interface-size • Template specialisation template <class CharType, class Attr=char_traits<CharType>, class Allocator=allocator<T>> class basic_string { … }; typedef basic_string<char> string; Beyond 2k Beyond OO

  10. Aspect-Oriented Programming • The need - poor modularity: • shared resources (locking) • multi-object protocols • error handling • complex performance optimisations • The solution - crossing boundaries: • crosscutting concerns in one source file (aspect) • weaver or pre-processor to scatter the aspects Beyond 2k Beyond OO

  11. AOP - OO Example Monitoring of a system’s state. The “system”: public class Variable { private int v; public Variable() { v = 0; } public int getV() { return v; } public void setV(int v) { this.v = v; } } Beyond 2k Beyond OO

  12. AOP - Monitoring Monitoring: displaying the state on each change Solutions: • producer-observer pattern(needs to subclass from a specific class) • introspection - catching method calls(needs special run-time architecture like Component Filters; has runtime overhead) Goal: • do not modify the original source (by hand) • do not add unnecessary run-time complexity Beyond 2k Beyond OO

  13. AOP - Aspect Monitoring code: aspect Trace { advise * Variable.*(..) { static before { System.out.println("Entering " + thisJoinPoint.methodName + " v=" + thisObject.v); } static after { System.out.println("Exiting " + thisJoinPoint.methodName + " v=" + thisObject.v); } } } Beyond 2k Beyond OO

  14. AOP - AspectJ • Implementation: Java/AspectJ from Xerox • weaver: general-purpose source level preprocessor • crossing normal visibility borders • adding new methods • adding common private variables • code segments before and after old methods • affecting otherwise unrelated classes Beyond 2k Beyond OO

  15. AOP - Woven public class Variable { private int v; public Variable() { v = 0; } public int getV() { int thisResult; System.out.println("Entering "+"getV"+" v="+this.v); thisResult = v; System.out.println("Exiting "+"getV"+" v="+this.v); return thisResult; } public void setV(int v) { System.out.println("Entering "+"setV"+" v="+this.v); this.v = v; System.out.println("Exiting "+"setV"+" v="+this.v); } } Beyond 2k Beyond OO

  16. AOP - Coexistence with OO • Aspects reduce code repetition • improves readability • improves maintainability • Mature OO design can be applied in large-scale • Aspects may be written in any language(weaver implementation is the only limitation) Beyond 2k Beyond OO

  17. Functional programming languages • Functional program = a set of function definitions + an expression to be evaluated • Usual properties • support parametric polymorphism(see Generic Programming) • advance program correctness • flexible manipulations with functions • co-exist with object-oriented programming Beyond 2k Beyond OO

  18. FP - Parametric Polymorphism • modern functional languages (ML, Miranda, Haskell, Clean) length :: [a] -> Int // optional type specification length [] = 0 length [first:rest] = 1 + length rest • application: length [1,2,3,4] evaluates to 4 • applicable to lists regardless of base type • only one compiled function, used everywhere Beyond 2k Beyond OO

  19. FP - Program Correctness (1) • correct programs are hard to write • formal methods • testing • formal methods are often hard to use in practice • code is too large (complexity explosion) • gap between specification and implementation • solutions • object-oriented programming • functional programming Beyond 2k Beyond OO

  20. FP - Program Correctness (2) What does OOP offer? - implementation decisions encapsulated in objects + reduce complexity by appropriately structuring the program + (sometimes does not work -> see GP, AOP) - model the real world + objects and their relations correspond to entities of the real world + solve the problem in the problem domain Beyond 2k Beyond OO

  21. FP - Program Correctness (3) What does FP offer? (1) - executable specifications + radically reduce the gap between specification and implementation + support abstraction by focusing on "what" instead of "how" qsort [] = [] qsort [x:xs] = qsort [y <- xs | y<x] +++ [x] +++ qsort [y <- xs | y>=x] Beyond 2k Beyond OO

  22. FP - Program Correctness (4) What does FP offer? (2) - forces programming without side-effects + easy to reason about programs + simple mathematical machinery + semi-automatic proof tools Beyond 2k Beyond OO

  23. FP - Manipulations with computations (functions) • functions as parameters or results + example: the "map" function, element wise processing on a list:map inc [1,2,3,4] evaluates to [2,3,4,5] + similar possibilities are already present • pointers to functions in C • subprogram types in Modula 2 • functions as generic parameters in Ada • greater flexibility, increased expressive power + e.g. currying: partial applications: map ((+) 2) [1,2,3,4] evaluates to [3,4,5,6] Beyond 2k Beyond OO

  24. FP - co-existence with OOP modern func. langs support many OOP concepts • abstract data types by type classes - allow alternative representations - similar to Java interfaces class Stack s e where instance Stack [e] e where push :: s e -> s push list elem = [elem:list] pop :: s e -> s pop [first:rest] = rest top :: s e -> e top [first:rest] = first • record types with functional components • powerful dynamic binding • existential types -> inhomogeneity • encapsulation (modules, abstract datatypes) • subtyping, inheritance and dynamic types Beyond 2k Beyond OO

  25. FP - Conclusion • functional programming can co-exist with OOP • the marriage endows OOP with valuable properties • promising future (efficiency problems are disappearing, e.g. Clean) Beyond 2k Beyond OO

  26. Component-oriented programming • New trend in the development of software applications is away from closed systems towards open system. • Opens systems must be ˝open˝ in at least three ways: topology platform evolution Beyond 2k Beyond OO

  27. Component-oriented programming • Topology • Open applications run on configurable networks. • Platform • The hardware and software platforms are heterogeneous. • Evolution • Requirements are unstable and constantly change Beyond 2k Beyond OO

  28. Object-Oriented Software Development • It partially addresses these needs by hiding data representation and implementation details behind object-oriented interfaces, thus permitting multiple implementations of objects to coexists while protecting clients from changes in implementation or representation. Beyond 2k Beyond OO

  29. Evolution II. • Evolution is only partially addressed, however, since changes in requirements may entail changes in the way that the objects are structured and configured. • It is necessary to view each application as only one instance of a generic class of applications, each built up of reconfigurable software components. Beyond 2k Beyond OO

  30. Component • The notion of component is more general than that of an object, and in particular may be of either much finer or coarser granularity. • An object encapsulates data and its associated behavior, whereas a component may encapsulate any useful software abstraction. Beyond 2k Beyond OO

  31. From Methodological Aspect • A component is a component because it has been designed to be used in a compositional way together with other components. It is designed as part of a framework of collaborating components. Components need not be classes and frameworks need not be abstract class hierarchies. Beyond 2k Beyond OO

  32. Examples • Valid examples of components may be: functions macros procedures templates modules Beyond 2k Beyond OO

  33. From Technical Aspect • At a software technology level, the vision of component-oriented development is a very old idea, which was already present in the first developments of structured programming and modularity. Beyond 2k Beyond OO

  34. Implementation • Component-oriented software development is not easy to realize for both technological and methodological reasons. • For a programming language to support component-oriented development, it must integrate both computational and compositional aspects of software development. Beyond 2k Beyond OO

  35. Computational and compositional aspects • An application can be viewed simultaneously as a computational entity that delivers results and • as a construction of software components that fit together to achieve those results. Beyond 2k Beyond OO

  36. Integration • The integration of these two aspects is not straightforward, since their goals may conflict. For example concurrency mechanisms, which are computational, may conflict with inheritance, which is a compositional features Beyond 2k Beyond OO

  37. Semantic Foundation • In order to achieve a clean integration of computational and compositional features a common semantic foundation is needed in which one may reason about both kinds of features and their interplay. • The key concepts of such foundations are:objects functions agents. Beyond 2k Beyond OO

  38. Exact Notion of Components • A component is a static abstraction with plugs • Static • By ˝static˝, we mean that a software component is a long-lived entity that can be stored in a software base, independently of the applications in which it has been used. • Abstraction • By “abstraction”, we mean that a component puts a more or less opaque boundary around the software it encapsulates. • With plugs • “With plugs” means that there are well-defined ways to interact and communicate with the component (parameters, ports, messages, etc.) Beyond 2k Beyond OO

  39. Outside view of a component • Seen from the outside, a component is a single entity, which may be moved around a copied , and in particular may be instantiated in a particular context, where the plugs will be bound to values or to other components. Beyond 2k Beyond OO

  40. Technical Support • Component-oriented software development not only requires a change of mind-set and methodology but it also requires new technological support. Beyond 2k Beyond OO

  41. Technical Support II. • Some issues that arise: • paradigm and mechanism for binding components together • structure of a software component • characterization of the composition process • formal model of components and composition, • verification method of correct compositions • concurrent computational model and software • composition. Beyond 2k Beyond OO

  42. Assembling Components • The fundamental composition mechanisms are the following: - functional composition - blackboard - extensibility. Beyond 2k Beyond OO

  43. Functional composition • This is the most fundamental composition mechanism. In this paradigm one entity is first encapsulated and parameterized as a functional abstraction, and is instantiated by receiving arguments that are bound to its parameters. This compositional mechanism occurs in nearly every programming environment not only in functional programming languages. Beyond 2k Beyond OO

  44. Blackboard • Agent environments use a global composition mechanism often called a blackboard. • A blackboard is a shared space, known by every component, in which information can be put and retrieved at particular locations. For systems of agents communicating through channels, the blackboard is the global space of channel names. Beyond 2k Beyond OO

  45. Extensibility • Object-oriented systems have introduced a new paradigm for software composition with the notion of extensibility - the possibility of adding functionality to a component while remaining “compatible” with its previous uses. • Extensibility is obtained in object-oriented languages through inheritance Beyond 2k Beyond OO

  46. Structure of a Software Component • Components are static entities; moreover, they always consists of some kind of abstraction. • Static software entities are procedures, functions, modules, classes etc. - A procedure is an abstraction for a sequence of instructions. - A class is an abstraction for a collection of objects. - A module is a a set of named abstractions. • All software components are treated as first-class values that can be passed as parameters to other components. Beyond 2k Beyond OO

  47. The Composition Process • A component -oriented lifecycle is needed. Beyond 2k Beyond OO

  48. Verification of Composition • Whenever components are assembled to perform a common task, there is always an implicit contract between them about the terms of the collaboration. • Two approach can be taken for dealing with verifying the correctness of a configuration: - Meyer’s approach used in Eiffel - improve the expressiveness of type system. Beyond 2k Beyond OO

  49. Concurrency and Components • Features needed to model in a language that supports component-oriented development: - Active Objects: objects can be viewed as autonomous agents or processes. - Components: they are abstractions over the computational space of active objects. - Composition: generalized composition is supported, not just inheritance. - Types: both objects and components have typed interfaces. - Subtypes: subtyping should be based on a notion of “plug compatibility“. Beyond 2k Beyond OO

  50. Conclusion Old and new paradigms could/should live together: multi-paradigm programming Advantages: • OO: mature large-scale design, good modularity • GP: parametrised type constructs • AOP: crosscutting concerns • FP: formal-proof, data-flow optimisation • Components: easy deployment and configuration Beyond 2k Beyond OO

More Related