Presentation is loading. Please wait.

Presentation is loading. Please wait.

© S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester 1 1998 Lecturer: Sita Ramakrishnan

Similar presentations


Presentation on theme: "© S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester 1 1998 Lecturer: Sita Ramakrishnan"— Presentation transcript:

1 © S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester 1 1998 Lecturer: Sita Ramakrishnan email: sitar@insect.sd.monash.edu.au

2 © S Ramakrishnan, Monash University oops1.ppt 2 OO Concepts & Terminology u OOP based on 4 key software engineering principles: u Abstraction u Encapsulation u Inheritance u Polymorphism

3 © S Ramakrishnan, Monash University oops1.ppt 3 Abstraction u A simplified specification of a system that emphasises some of the systems’ details while suppressing others (M Shaw: Abstraction techniques in Programming)

4 © S Ramakrishnan, Monash University oops1.ppt 4 Data Abstractions u users focussing on the essential features of the object, based on their perspective u CAR - licence plate, premium due,... (RACV) u CAR - service records, rego due,... (Owner)

5 © S Ramakrishnan, Monash University oops1.ppt 5 Encapsulation u Datatype, data and operation bundled together as a unit u compared to traditional programming model where u data allocated in memory u data manipulated by code from subroutines or functions

6 © S Ramakrishnan, Monash University oops1.ppt 6 Encapsulation u Wrapped up (encapsulated) object contains data and code u Protected from arbitrary access by other code - access only through public interfaces u Basis of Encapsulation is a Class in Eiffel

7 © S Ramakrishnan, Monash University oops1.ppt 7 Inheritance u OOP enables users to build on a class that is already defined u Ability to declare a new type from existing type by building on the data and methods of the existing type u Inherited class - case of specialization or extension or replacement of parent features

8 © S Ramakrishnan, Monash University oops1.ppt 8 Inheritance u view real world objects with hierarchical relationships u to define an Account in an abstract way, consider their attributes & behaviours u account attributes - account number, overdraft allowed,... u account behaviours (operations) - deposit, display,...

9 © S Ramakrishnan, Monash University oops1.ppt 9 Inheritance u Describe a more specific class of Account u cheque_account with more specific attributes & operations u In OOPs, declare that new type is related to existing Account class u program only the differences between the 2 types

10 © S Ramakrishnan, Monash University oops1.ppt 10 Inheritance u is-a relationship u subtype is-a Type (Class) with additional functionality u CHEQUE_ACCOUNT is-a ACCOUNT with... u CONFERENCE_ATTENDEE is-a PERSON with... u for operations e.g. display that apply to both object types - one can provide either object u compare with client-supplier relationship re: encapsulation

11 © S Ramakrishnan, Monash University oops1.ppt 11 Polymorphism u Greek term for many shapes u use the same name to refer to various methods - name sharing u 2 types - i) overloading, ii)true polymorphism u i) use same name for various methods in a class - types or no. of parameters different - so compiler can know which synonym to use u i) eg. smell method in DOG Class with cat or food objects as parameters - show behaviours - bark or run to eat!

12 © S Ramakrishnan, Monash University oops1.ppt 12 Polymorphism u ii) True Polymorphism - resolved at run time u subclass has a method with the same name & signature (type, number & order of parameters) as the parent class method u if that is so, subclass method overrides superclass method u eg: serve method in Vegetable & subclass Green Salad - correct serve chosen at run time based on which object is referred to - polymorphism

13 © S Ramakrishnan, Monash University oops1.ppt 13 Polymorphism u Overloading resolved by the compiler at compile time (static) - inflexible u compiler chooses one from a no. of methods with the same name by matching on argument types u Overriding resolved at run time u extend functionality by subclassing - ability to override u choosing the correct method - late binding u Polymorphism - language feature that allows 2 methods with same name - such that late binding may be applied

14 © S Ramakrishnan, Monash University oops1.ppt 14 Polymorphism u information passed to methods on objects as parameters to method invocation u parameters - list of typed values that make up input data to a particular message u method - can be viewed as a parameterised message u compare to trad. prog - different operations need separate functions with different names


Download ppt "© S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester 1 1998 Lecturer: Sita Ramakrishnan"

Similar presentations


Ads by Google