1 / 13

Chapter 10 Thinking in Objects

Chapter 10 Thinking in Objects. Principle of OOP. Inheritance Abstraction Encapsulation Polymorphism Also know as (APIE). Inheritance and Composition. A class can extend another class. Inheritance implements the “ IS a” relationship between objects

rjohns
Download Presentation

Chapter 10 Thinking in Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 10 Thinking in Objects

  2. Principle of OOP • Inheritance • Abstraction • Encapsulation • Polymorphism • Also know as (APIE)

  3. Inheritance and Composition • A class can extend another class. • Inheritance implements the “ IS a” relationship between objects • A class can implements interface, methods members from its parent class.

  4. Inheritance and Composition • Is- A and Has –A • Inheritance VS Composition • Favor Composition • Polymorphism • Interfaces

  5. Is-A and Has-A relationship • Classes depend on another class • Classes are related via Is –A or Has –A relationship • Cat-> Animal = IS-A • Car->Wheel, Engine =Has -A • Train->Wheel,Engine=Has -A • Car,Truck-> Vehicle= Is-A • HAS-A=Composition (compose) IS-A=Inheritance(subtype) • Reuse code

  6. Inheritance (Is-A) • Animal is a base class cat class inheritances from animal Animal Cat

  7. Inheritance Syntax Java Supports only public inheritance A is a Superclass and B is a Subclass

  8. Inheritance Syntax In order to call the constructor of superclass(A) the keyword super is used

  9. Composition (Has-A) • Something is made up of other parts • Car contains wheel and engine • It is also called aggregation car wheel Engine

  10. Composition (Has-A):aggregation Composition(HAS-A) simply mean use of instance variables that are references to other objects. For example: Maruti has Engine, or House has Bathroom

  11. Composition (Has-A):aggregation

  12. Aggregation Lab

  13. Inheritance Lab • Follow the instructions provided on Lab9

More Related