Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Open/Closed

The usual definition of the Open/Closed Principle states that “software entities should be open for extension but closed for modification”. Sounds great, but what does that mean, exactly? It means, essentially, that extending the functionality of an entity (class or member) shouldn’t require changes to any other code, whether in that entity or another.

Like many principles, OCP can be easier to understand in its breach, so let’s look at an example of code that isn’t immune from changes. You might remember that some of the recipe components are made in-house, and others are purchased. So what happens when our chefs need more of something? Here’s a version of our class diagram that reflects the two types of ingredients:

image

The Open Closed Principle


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial