Presentation is loading. Please wait.

Presentation is loading. Please wait.

lecture 08, OO Design Principle

Similar presentations


Presentation on theme: "lecture 08, OO Design Principle"— Presentation transcript:

1 lecture 08, OO Design Principle
OO Design Principles 11/24/2018 lecture 08, OO Design Principle

2 lecture 08, OO Design Principle
The Open-Closed Principle: Software Entities Should be Open For Extension, Yet Closed For Modification 11/24/2018 lecture 08, OO Design Principle

3 Open-Closed Principle
The open-closed principle (OCP) says that we should attempt to design modules that never need to be changed. To extend the behavior of the system, we need to add code. We do not modify old code Modules that conform to OCP meet two criteria: Open for Extension – the behavior of the module can be extended to meet new requirements Closed for modification – the source code of the module is not allowed to change How can we do this Inheritance Abstraction Polymorphism Interface 11/24/2018 lecture 08, OO Design Principle

4 Open-Closed Principle
It is not possible to have all the methods of a software system satisfy the OCP, but we should minimize the number of modules that do not satisfy it. The OCP is really the heart of OO design Conformance to this principle yields the greatest of reusability and maintainability. 11/24/2018 lecture 08, OO Design Principle

5 lecture 08, OO Design Principle
OCP Example In the Video Store example, we use inheritance to represent the different categories of a Movie. When a new category of a movie comes in, you don’t need to modify the existing code. Just add another subclass of class Movie. Without a subclass, what construct should be used to support different categories of a Movie class? 11/24/2018 lecture 08, OO Design Principle


Download ppt "lecture 08, OO Design Principle"

Similar presentations


Ads by Google