Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods) (module) Software reuse & modification (extension or restriction) 1. Extension of data or operations 2. Redefinition of operations 3. Application Frameworks (redefinition for specific cases) 4. Abstraction (& re factoring) 5. Polymorphism: overloading & parametrised types E.g. sequence stack with add & remove at position 1 E.g. sequence deque (double ended queue) 1DFR - PL - OO Paradigm
Object Oriented Paradigm Smalltalk Concepts Class class attributes; object attributes; methods Object instance of a class (class attributes; methods) Messages request for a service; performed by a method may include parameters; may return a result mutators may change the state of the object Variable reference semantics (not value) ref to object Inheritance class hierarchy Polymorphism overloading (same name for similar services) Collection types (Object(Collection (Bag) (Indexed (FixedSize (Array) (String)) (Ordered (Sorted))) (Set (Dictionary))) No built in classes for stacks, queues, trees or graphs 2DFR - PL - OO Paradigm
Object Oriented Paradigm Java Concepts (C/C++ like syntax) Class class attributes; object attributes; methods (static) reference semantics BUT primitive types: int, float, char value semantics Object instance of a class (class attributes; methods) instance variables (usually private) self reference: this, self Method operation on an object; accessor (get), mutator (set) abstract signature(sub class implementation) access control: public; protected; private constructor (prologue) ; destructor (epilogue); Packages e.g. string Garbage Collection 3DFR - PL - OO Paradigm
Object Oriented Paradigm Java Collection Framework concepts Interfaces e.g. list, queue Generic collections type parameters Static Binding (compile time) & Dynamic Binding (run time) Map transform each element in a collection Filter select elements from a collection Reduce summarise information about a collection e.g. # these 3 ideas come from functional programming recall the remove if, count if in Lisp 4DFR - PL - OO Paradigm
Object Oriented Paradigm C++ Concepts Class class attributes; object attributes; methods similar to the struct in C Super class base class Sub class derived class Members instance variables data members methods member functions Access control public, protected, private Constructors & Destructors Generic Collection Template Class STL Standard Template Library Static Binding, Dynamic Binding Virtual Functions 5DFR - PL - OO Paradigm
Design Issues in OOPLs More dynamic operations (run time overhead) Classes versus Types Objects are typeless classes not type checked Classes are type constructors classes part of the type system Classes become the type system Classes versus Modules Implementation + interface not always well separated Extra module mechanism Java packages, C++ namespace C++ friend open access to external operations Inheritance versus Polymorphism Parametric polymorphism type parameters unspecified Overloading (ad hoc polymorphism) name overloaded Subtype Polymorphism all ops on one type applied to another Inheritance sub type / overloading 6DFR - PL - OO Paradigm
Implementation Issues in OOPLs Objects and Methods Objects implementation as record structures Methods implementation as functions (+ object ref param) Inheritance and Dynamic Binding Which method may not be known until run time Allocation (Heap/Stack) and Initialisation Stack allocation compiler generates constructor Initialisation of ancestor class scheduled by the compiler Garbage collection automatic or programmer controlled? FINAL COMMENTS Many of these issues are language dependent Although widespread, the OOP has received criticism! 7DFR - PL - OO Paradigm
Critique! Joe Armstrong, (Erlang), who is quoted as saying: [34] The problem with object oriented languages is they've got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle. https://en.wikipedia.org/wiki/object oriented_programming#criticism 8DFR - PL - OO Paradigm
Issues to explore! Definitions of OOP and OOPLs are they the same? Simula 67 & Smalltalk (history) C C++ Java C# development (pointers!!!) Class based versus Prototype based The ellipse circle criticism Complexity issues more design required Composition & Inheritance (single & multiple) Design patterns Application areas suitable / less suitable Relationship to other paradigms Learning overhead 9DFR - PL - OO Paradigm
Summary & Final Comments OO concepts existed already in the 1960s Historically Simula 67 the first OOPL, Smalltalk pure OOPL Developed during 1980s in use 1990s The application of the OOP was often not successful Programmers wrote code but did not always understand OOP!!! Can lead to more complexity if not understood The object oriented paradigm is NOT well defined Developed through languages e.g. C++ was C compatible C++ considered dangerous (pointers) Java (references) C++ / Java / C# are more used because of the syntax There is a substantial body of criticism on OOP There is no FORMAL base for OOP (cf functional / logic) DFR - PL - OO Paradigm 10