Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inheritance Allows extension and reuse of existing code

Similar presentations


Presentation on theme: "Inheritance Allows extension and reuse of existing code"— Presentation transcript:

1

2 Inheritance Allows extension and reuse of existing code
Derived class can access base class properties and still the derived class has its own properties

3 A generic Example

4 Inheritance in Railway Reservation System
Passenger is a person Employee is a person E-ticket is a ticket I-ticket is a E-Ticket (Multi level Inheritance)

5

6

7 Look alike but exhibit different characters

8 Polymorphism Derived from the Greek many forms
Single name can be used for different purposes Different ways of achieving the polymorphism: 1. Function overloading 2. Operator overloading 3. Dynamic binding

9 Polymorphism Languages exhibit polymorphism through operators
"+" for addition of reals and integers or "-" for unary negation or arithmetic subtraction. Therefore the same operation is performed on different data types with out changing the basic meaning of the operation.  ‘*’ is overloaded for multiplication and as dereference operator

10 Static Vs Dynamic binding
Routing a call to a landline/mobile phone Binding->Tie up of a call to the address code to be executed in response to a call Landline – Static routing Mobile Phones – Dynamic binding Behavior of the object determined only at runtime Also called as late binding

11 Polymorphism in Railway Reservation System
Search a train – Search by train number, name etc – Function Overloading [], -, + - Operators shall be overloaded for knowing details of a coach in a train, add or remove a coach from a train

12 Polymorphism in Railway Reservation System
ComputeSalary function shall be made as pure virtual function and implemented in dervied classes regular employee, daily wages employee etc

13 Message passing  Sending and receiving of information by the objects same as people exchange information Invoking an operation on an object To invoke an operation is based on the name of the operation and the class of the object being operated. Shall be interpreted as a request for the execution of a function.

14 Message Passing in Railway Reservation System
Know the availability of seats in a coach during reservation Interaction is between the ticket object and the coach object Ticket makes a request and coach returns the availability

15 Persistance Phenomena by which object outlives the program execution and exists between executions of a program Not supported in C++

16 Delegation Receiving object may delegate operations to other objects
Eg: Child class can delegate the request to parent class Age of a passenger Requested will be delegated to parent class - person

17 Genericity Defines the software with more than one interpretation depending on the data type of parameters Thus, it allows the declaration of data items without specifying their exact data type. Such data types are solved at the time of their usage. This can be realized through the “function template” and “class template”

18 Genericity in C++ Function templates – Sort coaches by capacity, by class (First, Second, third), coach position Class templates – Stack ADT, linked list, Queues etc

19 There are two kinds of Relationships
OO Relationships There are two kinds of Relationships Generalization (parent-child relationship) Association (student enrolls in course) Associations can be further classified as Aggregation Composition

20 OO Relationships: Generalization
Supertype Example: Customer Regular Customer Loyalty Customer Subtype1 Subtype2 or: Customer - Generalization expresses a parent/child relationship among related classes. - Used for abstracting details in several layers Regular Customer Loyalty Customer

21 OO Relationships: Association
Represent relationship between instances of classes Student enrolls in a course Courses have students Courses have exams Coach is connected to a train Association has two ends Role names (e.g. enrolls, connected) Multiplicity (e.g. One course can have many students, one train may have many coached)

22 How to create the class “Account” in dia?
accno:int acctype:String name:String balance:float deposit(a:int):void withdraw(a:int):int enquire():String

23 Choose the option “UML”
From the select box

24 Select the class from the tool bar and Drag and drop it in to the canvas
Select “class”

25 Double click the compartment “Class”

26 Edit the class name as “Account”

27 Now choose the Tabbed button “Attributes” to name the attribute

28 Press the button “New” to enable the “Attribute data” fields and edit the fields(name,type and visibility)

29 Now press the button “New” to add more attributes and finally press “ok”

30 Similarly, choose the Tabbed button “Operations” to add the operations
Press “New” to enable the parameter data fields

31 Adding parameters and type and press ok

32 Use the same procedure to add other methods

33 A sample showing the “Association” relationship
Double click the association link for setting the properties

34 A sample showing the generalization relationship


Download ppt "Inheritance Allows extension and reuse of existing code"

Similar presentations


Ads by Google