Download presentation
Presentation is loading. Please wait.
1
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 1 Object-Oriented Programming Languages Principles of Object-Oriented Software Development (Chapter 5)
2
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 2 Objective l To illustrate the concepts of object-oriented programming languages in a broader context beyond the familiar Java and C++ interpretations.
3
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 3 Outline l The object paradigm l Comparison: Smalltalk, Eiffel, C++, Java l Dimensions of language design l Classless languages
4
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 4 The Notion of Object l The notion of objects appears in many areas of computer science Software engineering: Abstract data types Artificial intelligence: Frames Databases: Semantic data models Distributed systems: Capability-based computing
5
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 5 Perspectives on Object-Orientation l Structural Capability of representing arbitrarily structures complex objects An object is a data structure in memory l Operational The ability to operate on complex objects through generic operators An object represents an element of a conceptual model l Behavioral The specification of types and operations An object is a type, used for data abstraction
6
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 6 Characteristics of Object- Oriented Languages l Object creation facility Must be able to instantiate objects l Message-passing capability Must be able to communicate between objects l Class capability Must have a mechanism for defining classes l Inheritance features Must support some form of inheritance
7
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 7 Classifications of Object-Oriented Languages l Hybrid – extensions to existing languages O-O retrofitted to existing languages: C, Lisp, Pascal, Prolog, etc Examples: C++, CLOS, Objective Pascal, DLP l Frame-based – knowledge-based reasoning Frame – a structure consisting of slots Slot – a value of an attribute or a relation to other frames Examples: KRL, LOOPS
8
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 8 Classifications (continued) l Distributed, concurrent, actor – parallel computing Active object – executes in parallel with other active objects Examples: Concurrent Smalltalk, sC++, POOL-T Actor languages Instead of threads, parallel execution is realized by self- replacement Actor processes a message sent to it, and creates a successor object in its place, thus the same actor potentially takes on a different identity l Alternative object models Removes the distinction between classes and objects Everything is an object Examples: Self
9
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 9 Object-Oriented Scripting Languages l Many scripting languages are designed to support object-oriented programming Built-in support Embedding an O-O language l Javascript l Perl, JPL (Java-Perl module) l Tcl/Tk, Jacl (Tcl/Java) l Python, JPython
10
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 10 Objects in Javascript function object_display(msg) { object method return msg + ' (' + this.variable++ + ')'; } function myobject() { object constructor this.variable=0; this.display = object_display; return this; } var a = new myobject(); create object document.write(a.display("a message")); document.write(a.display("another message"));
11
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 11 Outline l The object paradigm l Comparison: Smalltalk, Eiffel, C++, Java l Dimensions of language design l Classless languages
12
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 12 Comparing Smalltalk, Eiffel, C++ and Java l Criteria Class libraries Availability of sufficient class library support Programming environment Availability of environment to support development Language characteristics
13
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 13 Smalltalk Example Behavior subclass: #Ctr instanceVariableNames: 'value' Ctr methodsFor: 'initialization' initialize value := 0. Ctr methodsFor: 'modifications' add: aValue value := value + aValue. Ctr methodsFor: 'inspection' value ^value
14
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 14 class counter export inc val feature count : Integer create is do count := 0 end inc( n : Integer ) is require n > 0 do count := count + n ensure count = old count + n end val : Integer is do Result := count end invariant count >= 0 end -- class counter Eiffel Example
15
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 15 C++ Example class ctr { public: ctr() { n = 0; } // constructor ~ctr() { cout << "bye"; }; // destructor void add( int i = 1) { n = n + i; } int val( ) { return n; } private: int n; }; // Usage: ctr c; c.add(1); cout << c.val(); ctr* p = new ctr(); c->add(1); cout val();
16
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 16 Class Libraries l Availability of sufficient class library support l Smalltalk: part of language definition l Eiffel: part of language definition l C++: STL, large number of 3 rd party libraries l Java: large number of standardized APIs
17
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 17 Programming Environment l What constitutes “good” programming environment? Graphical interface for novices Command line interface for experts l Smalltalk: part of language definition l Eiffel: part of language definition l C++: large number of commercial environments l Java: many popular IDEs (Eclipse, JBuilder, Visual J#, JDeveloper, NetBeans)
18
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 18 Language Characteristics l Uniformity of data structures l Documentation value l Reliability l Inheritance mechanism l Efficiency l Memory management l Language complexity
19
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 19 Comparison Table
20
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 20 Uniformity l Uniformity of treatment of data types l Smalltalk Every data type is a class l Eiffel Elementary data types are distinct from classes l C++ Elementary data types are distinct from classes l Java Elementary data types are distinct from classes
21
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 21 Documentation Value l How easy is it to read a program and to write a correct program? l Smalltalk A consistent style in writing programs because everything is a class l Eiffel Special keywords to formally specify correctness of programs and specify interfaces l C++ No constructs to support documentation Terse style is preferred by some over the more verbose languages l Java Javadoc sets a standard for documentation
22
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 22 Reliability l Smalltalk Dynamically typed, no type checking l Eiffel Static type checking, correctness assertions l C++ Inherits unreliability perception from C Static type checking within a compilation module, weak support across modules Consistent type system l Java Less error-prone than C++ due to absence of pointers and built- in garbage collection
23
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 23 Inheritance l Smalltalk Single inheritance l Eiffel Multiple inheritance l C++ Multiple inheritance l Java Single inheritance Multiple interface inheritance
24
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 24 Efficiency l Smalltalk –Interpreted l Eiffel +Compiled –Dynamic binding for all methods l C++ +Compiled +Inline functions, flexible memory management, friends –No garbage collection l Java –Compiled to bytecode; efficiency depends on JVM
25
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 25 Language Complexity l Smalltalk Generally considered low complexity l Eiffel Simple object-oriented constructs l C++ Highly complex Large language; complicated overloading l Java Designed to be less complex than C++
26
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 26 Outline l The object paradigm l Comparison: Smalltalk, Eiffel, C++, Java l Dimensions of language design l Classless languages
27
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 27 Design of Object-Oriented Languages l Object-oriented languages support the following: Object – state + operations Class – template for object creation Inheritance – sharing parts of a description Data abstraction – state accessible by operations Strong typing – compile time checking Object-oriented = objects + classes + inheritance Object-based = objects + classes
28
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 28 Orthogonal Dimensions l More formally, object-oriented languages can be defined by the following orthogonal dimensions: Objects – modular computing agents Supports construction of modular units to which a principle of locality applies Types – expression classification Types are a more general abstraction than classes Dynamic typing – no static type checking, only inability to evaluate an expression leads to runtime error Static typing – compile time determination and checking of the types of all variables, objects and expressions Delegation – resource sharing A mechanism that allows redirection of control dynamically A more general mechanism than forwarding a method call Examples: single inheritance, multiple inheritance, scope inheritance Abstraction – interface specification What is visible and what is hidden to other objects? External behavior specified by contracts External state specified by public or protected attributes
29
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 29 Open Systems l A goal of object-oriented language design is openness l A software system is said to be open if its behavior can be easily modified and extended l Reactiveness A program has a (runtime) choice between potential actions l Modularity A program can be safely extended (at design time) by adding new components
30
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 30 Reactiveness l A program has a (runtime) choice between potential actions l Late binding (polymorphism) provides dynamic selection of alternatives depending on the subtype l Guards in concurrent languages provide a choice for accepting or rejecting a call
31
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 31 Modularity l A program can be safely extended (at design time) by adding new components l Languages must provide appropriate information hiding mechanisms: Hide details of objects from outside world Usual notion of encapsulation Classes provide modularity by hiding details of the class from the outside world Hide details of outside world from objects Objects should not have to know that other objects are on the same machine or not Objects should not have to know that other objects are active
32
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 32 Object-based Concurrency l Object-based concurrency = objects + processes l Approaches Add processes as a primitive data type Programmer has the burden of dealing with synchronization Implement active objects Objects are simultaneously active Language provides constructs to support synchronous communications (rendezvous) Active object interrupts itself to respond to messages Potential for deadlock exists with self-invocation Performance issues if only a few active objects needed Need careful choice in determining which objects should be active Use asynchronous communication through message buffers Instead of interrupting, queue up the messages in a buffer Real-time constraints become impossible to guarantee
33
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 33 Outline l The object paradigm l Comparison: Smalltalk, Eiffel, C++, Java l Dimensions of language design l Classless languages
34
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 34 Classless Languages l Classical object model Objects are instances of classes Object-oriented = objects + classes + inheritance l Classless languages There are no classes, only objects New objects are created by cloning existing objects Objects are cloned from objects called “prototypes” Inheritance is approximated by delegation Object chooses which object to designate as parent Dynamic binding is implemented by searching up the parent list Advantages Conceptually easier to create objects from existing examples rather than defining a characterization of the object through a class Dynamic sharing of code and information is more flexible than inheritance and instantiation
35
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 35 Design Issues for Prototypes l State Object consists of slots Object consists of variables and methods l Creation Shallow cloning – copy the object Deep cloning – copy the object and all referenced objects l Delegation Implicit delegation – follow the parent chain Explicit delegation – object is named l Self language: slots, shallow cloning, implicit delegation
36
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 36 Improving Performance l In pure object-oriented languages, dynamic type checking and dynamic binding is the rule Increases flexibility Performance suffers l Solutions Special-purpose hardware Hybrid languages Create a hybrid language with a procedural language Dealing with unwanted interactions can be a complex problem Static typing Bounds the language flexibility Dynamic compilation Perform partial evaluation, lazy compilation, message splitting
37
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 37 Dynamic Compilation Techniques l Customized compilation l Message inlining l Lazy compilation l Message splitting
38
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 38 Meta-Level Architectures
39
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 39 The Class Concept l Abstract data type – interface description l Object generator – template for creation l Repository – for sharing resources l Object – instance of a metaclass
40
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 40 Meta Architectures
41
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 41 Postulates – class-based languages l Everything is an object l Every object belongs to a class l Every class inherits from the class Object l Class variables of an object are instance variables of its class
42
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 42 Reflective definition of Class
43
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 43 Summary l The object paradigm Notion of object – viewpoints Classification – object extensions l Comparing Smalltalk, Eiffel, C++ and Java Criteria – libraries, environments, language characteristics Comparison – language characteristics l Design dimensions of object-oriented languages Object-oriented Orthogonal dimensions Open systems l Prototypes Prototypes – cloning and delegation Performance – dynamic compilation l Meta-level architectures Class Meta architecture Reflection
44
Harvey SiyPrinciples of Object-Oriented Software Development by Eliens Slide 44 Summary l The object paradigm Notion of object – viewpoints Classification – object extensions l Comparing Smalltalk, Eiffel, C++ and Java Tradeoffs between pure and hybrid languages Flexibility versus performance l Design dimensions of object-oriented languages Object-oriented = objects + classes + inheritance Orthogonal dimensions: objects, types, delegation, abstraction Open systems are systems that can be easily modified and extended Classless languages use cloning and delegation instead of instantiation and inheritance
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.