Title: ObjectOriented Programming Languages
1Object-Oriented Programming Languages
- Principles of Object-Oriented
- Software Development
- (Chapter 5)
2Objective
- To illustrate the concepts of object-oriented
programming languages in a broader context beyond
the familiar Java and C interpretations.
3Outline
- The object paradigm
- Comparison Smalltalk, Eiffel, C, Java
- Dimensions of language design
- Classless languages
4The Notion of Object
- 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
5Perspectives on Object-Orientation
- Structural
- Capability of representing arbitrarily structures
complex objects - An object is a data structure in memory
- Operational
- The ability to operate on complex objects through
generic operators - An object represents an element of a conceptual
model - Behavioral
- The specification of types and operations
- An object is a type, used for data abstraction
6Characteristics of Object-Oriented Languages
- Object creation facility
- Must be able to instantiate objects
- Message-passing capability
- Must be able to communicate between objects
- Class capability
- Must have a mechanism for defining classes
- Inheritance features
- Must support some form of inheritance
7Classifications of Object-Oriented Languages
- Hybrid extensions to existing languages
- O-O retrofitted to existing languages C, Lisp,
Pascal, Prolog, etc - Examples C, CLOS, Objective Pascal, DLP
- 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
8Classifications (continued)
- 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 - Alternative object models
- Removes the distinction between classes and
objects - Everything is an object
- Examples Self
9Object-Oriented Scripting Languages
- Many scripting languages are designed to support
object-oriented programming - Built-in support
- Embedding an O-O language
- Javascript
- Perl, JPL (Java-Perl module)
- Tcl/Tk, Jacl (Tcl/Java)
- Python, JPython
10Objects in Javascript
ltscript languageJavascriptgt function
object_display(msg)
object method return msg
' (' this.variable ')'
function myobject()
object constructor
this.variable0 this.display
object_display return this
var a new myobject()
create
object document.write(a.display("a
message")) document.write(a.display("another
message")) lt/scriptgt
11Outline
- The object paradigm
- Comparison Smalltalk, Eiffel, C, Java
- Dimensions of language design
- Classless languages
12Comparing Smalltalk, Eiffel, C and Java
- Criteria
- Class libraries
- Availability of sufficient class library support
- Programming environment
- Availability of environment to support
development - Language characteristics
13Smalltalk 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
14Eiffel Example
class counter export inc val feature
count Integer create is do count 0 end
inc( n Integer ) is require n gt
0 do count count n ensure
count old count n end val
Integer is do Result count end
invariant count gt 0 end -- class counter
15C Example
class ctr public ctr() n 0
// constructor
ctr() cout ltlt "bye"
// destructor void add( int i 1) n
n i int val( ) return n
private int n // Usage ctr c
c.add(1) cout ltlt c.val() ctr p new ctr()
c-gtadd(1) cout ltlt c-gtval()
16Class Libraries
- Availability of sufficient class library support
- Smalltalk part of language definition
- Eiffel part of language definition
- C STL, large number of 3rd party libraries
- Java large number of standardized APIs
17Programming Environment
- What constitutes good programming environment?
- Graphical interface for novices
- Command line interface for experts
- Smalltalk part of language definition
- Eiffel part of language definition
- C large number of commercial environments
- Java many popular IDEs (Eclipse, JBuilder,
Visual J, JDeveloper, NetBeans)
18Language Characteristics
- Uniformity of data structures
- Documentation value
- Reliability
- Inheritance mechanism
- Efficiency
- Memory management
- Language complexity
19Comparison Table
20Uniformity
- Uniformity of treatment of data types
- Smalltalk
- Every data type is a class
- Eiffel
- Elementary data types are distinct from classes
- C
- Elementary data types are distinct from classes
- Java
- Elementary data types are distinct from classes
21Documentation Value
- How easy is it to read a program and to write a
correct program? - Smalltalk
- A consistent style in writing programs because
everything is a class - Eiffel
- Special keywords to formally specify correctness
of programs and specify interfaces - C
- No constructs to support documentation
- Terse style is preferred by some over the more
verbose languages - Java
- Javadoc sets a standard for documentation
22Reliability
- Smalltalk
- Dynamically typed, no type checking
- Eiffel
- Static type checking, correctness assertions
- C
- Inherits unreliability perception from C
- Static type checking within a compilation module,
weak support across modules - Consistent type system
- Java
- Less error-prone than C due to absence of
pointers and built-in garbage collection
23Inheritance
- Smalltalk
- Single inheritance
- Eiffel
- Multiple inheritance
- C
- Multiple inheritance
- Java
- Single inheritance
- Multiple interface inheritance
24Efficiency
- Smalltalk
- Interpreted
- Eiffel
- Compiled
- Dynamic binding for all methods
- C
- Compiled
- Inline functions, flexible memory management,
friends - No garbage collection
- Java
- Compiled to bytecode efficiency depends on JVM
25Language Complexity
- Smalltalk
- Generally considered low complexity
- Eiffel
- Simple object-oriented constructs
- C
- Highly complex
- Large language complicated overloading
- Java
- Designed to be less complex than C
26Outline
- The object paradigm
- Comparison Smalltalk, Eiffel, C, Java
- Dimensions of language design
- Classless languages
27Design of Object-Oriented Languages
- 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
28Orthogonal Dimensions
- 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
29Open Systems
- A goal of object-oriented language design is
openness - A software system is said to be open if its
behavior can be easily modified and extended - Reactiveness
- A program has a (runtime) choice between
potential actions - Modularity
- A program can be safely extended (at design time)
by adding new components
30Reactiveness
- A program has a (runtime) choice between
potential actions - Late binding (polymorphism) provides dynamic
selection of alternatives depending on the
subtype - Guards in concurrent languages provide a choice
for accepting or rejecting a call
31Modularity
- A program can be safely extended (at design time)
by adding new components - 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
32Object-based Concurrency
- Object-based concurrency objects processes
- 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
33Outline
- The object paradigm
- Comparison Smalltalk, Eiffel, C, Java
- Dimensions of language design
- Classless languages
34Classless Languages
- Classical object model
- Objects are instances of classes
- Object-oriented objects classes inheritance
- 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
35Design Issues for Prototypes
- State
- Object consists of slots
- Object consists of variables and methods
- Creation
- Shallow cloning copy the object
- Deep cloning copy the object and all referenced
objects - Delegation
- Implicit delegation follow the parent chain
- Explicit delegation object is named
- Self language slots, shallow cloning, implicit
delegation
36Improving Performance
- In pure object-oriented languages, dynamic type
checking and dynamic binding is the rule - Increases flexibility
- Performance suffers
- 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
37Dynamic Compilation Techniques
- Customized compilation
- Message inlining
- Lazy compilation
- Message splitting
38Meta-Level Architectures
39The Class Concept
- Abstract data type interface description
- Object generator template for creation
- Repository for sharing resources
- Object instance of a metaclass
40Meta Architectures
41Postulates class-based languages
- Everything is an object
- Every object belongs to a class
- Every class inherits from the class Object
- Class variables of an object are instance
variables of its class
42Reflective definition of Class
43Summary
- The object paradigm
- Notion of object viewpoints
- Classification object extensions
- Comparing Smalltalk, Eiffel, C and Java
- Criteria libraries, environments, language
characteristics - Comparison language characteristics
- Design dimensions of object-oriented languages
- Object-oriented
- Orthogonal dimensions
- Open systems
- Prototypes
- Prototypes cloning and delegation
- Performance dynamic compilation
- Meta-level architectures
- Class
- Meta architecture
- Reflection
44Summary
- The object paradigm
- Notion of object viewpoints
- Classification object extensions
- Comparing Smalltalk, Eiffel, C and Java
- Tradeoffs between pure and hybrid languages
- Flexibility versus performance
- 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