163. SOLID - Open-Closed Principle

13:57

Access AI content by logging in

As part two of our series that explores the SOLID software design principles, this episode dives straight into the topic of the open-closed principle — that’s the ‘O’ of SOLID for those who are counting. As a software principle created in 1988, back in the days of C++, the essence of this principle states that you should create code that’s “open for extension but closed for modification.” Using the example of needing to create a calculator that measures the areas of rectangles, we talk about how the open-closed principle makes it easier to create an extension to your area calculator if you suddenly need to calculate the area of a circle. While this principle makes it easier for developers to add features to your software, we discuss how needing to perform “shotgun surgery” on your code may be a sign that you haven’t adhered to the open-closed principle. For a real-world example, we share how we’ve implemented the open-closed principle into an intranet project that we’re developing. Near the end of the episode, we talk about how following the open-closed principle helps ensure that you’re following the other SOLID principles. Listen to this episode and learn how important the open-closed principle is to writing good code.