From the course: Programming Foundations: Design Patterns
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Understanding the open-closed principle
From the course: Programming Foundations: Design Patterns
Understanding the open-closed principle
- [Instructor] So where do we go from here? Let's begin by getting some insight from our next design principle, the open-closed principle. This principle says that classes should be open for extension but closed for modification. What does that mean? Well, think about our current design for the coffee shop. We know in the future we'll need to support new beverage types and new condiments but that means we'll have to modify existing code, and that's exactly what we don't want. We want to leave our design open for new beverage types and condiments but closed in the sense that we don't want to touch existing code. Let's look at this principle in a little more detail. Again, the open-closed principle says that code should be open for extension but closed for modification. If we can do that, we have flexibility and maintainability because we can add new behavior but without the risk of introducing new bugs into the code we've…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Creating chaos with inheritance4m 12s
-
(Locked)
Understanding the open-closed principle2m 49s
-
(Locked)
Extending behavior with composition2m 29s
-
(Locked)
Understanding the decorator pattern2m 23s
-
(Locked)
Using the Decorator pattern5m 6s
-
(Locked)
Challenge: The Decorator pattern40s
-
(Locked)
Solution: The Decorator pattern1m 22s
-
(Locked)
-
-
-