1 / 13

HFOOAD Chapter 5 Interlude

HFOOAD Chapter 5 Interlude. OO Catastrophe!. Two possible answers. Interface. Abstract class. Defines behavior Can have implementation code Cannot be instantiated A class can inherit from a single abstract class Unless the language supports multiple inheritance. Defines behavior

kelly-baird
Download Presentation

HFOOAD Chapter 5 Interlude

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. HFOOAD Chapter 5 Interlude OO Catastrophe!

  2. Two possible answers Interface Abstract class Defines behavior Can have implementation code Cannot be instantiated A class can inherit from a single abstract class Unless the language supports multiple inheritance • Defines behavior • Contract • Cannot be instantiated • A class can implement multiple interfaces • In languages that support interfaces

  3. How do I know when to use an interface and when to use an abstract class? If (almost) all classes implementing the behavior would have the same code, then you can use an abstract class to implement it. Avoid repeating code with abstract classes Program to interfaces

  4. ENCAPSULATION Isn’t encapsulation just about hiding implementation?

  5. Solution 1

  6. Solution 2

  7. Prefer delegation over inheritance

  8. Manage change Manage change Manage change … Change Change Change Change

  9. Final Catastrophe challenge

  10. Our solution

More Related