From the course: Advanced Design Patterns: Design Principles

What are design principles?

- [Instructor] Design principles are guidelines that help us improve our object-oriented design. We say they're guidelines because they're meant as advice, not some kind of absolute law that has to be followed. Think of design principles as common sense rules that have been observed to work in many situations, but not necessarily all situations. Another way to look at design principles is that they're meant to help us avoid bad object-oriented design. What a bad object-oriented design? Well, we could say it's design that is rigid. That is it's hard to change due to some dependencies. For instance, say you change one part of your application and it ends up leading to a whole cascade of changes throughout your entire application, that's rigid. Or it's a design that's fragile, as you make changes, do you keep getting unexpected bugs? That is if you make changes in your code, do things begin breaking in unrelated parts that you didn't expect? That's fragility. Or is your design immobile? In other words, is it hard to reuse? Can you take your design and easily reuse it in places it wasn't designed for, if not your designs immobile. All of these bad qualities lead to software that's inflexible, hard to maintain and not resilient to change, not what we want. But design principles are here to help. Design principles go beyond those core object-oriented principles. We all learned in our first object-oriented course, or that introductory object-oriented book, those fundamental concepts of inheritance, the concept that we can reuse features or behaviors of a class by inheriting from it. Encapsulation, we can hide and protect the data in a class. Polymorphism, the idea that we can write code that works for types, and their subtypes, and abstraction, where we can hide away implementation details only relying on a class type or an interface. And while many of us are taught to adhere to these fundamental concepts, you'll soon find if you haven't already, that doing so doesn't ensure good design, that is designs that are flexible and maintainable and reusable. In fact, blindly following these core concepts can often lead in the other direction to designs that have many of the bad qualities we just discussed. Design principles, they help us by giving us an additional set of guidelines on top of the core object-oriented concepts. They give us guidelines to help guide our designs. And these guidelines usually identified by a name or a short pithy phrase like a favor composition over inheritance. They give us key insights into how to and not to approach object-oriented design. And that is going to be the focus of this course, design principles. But let's not forget the goal of the series, advanced design patterns. Because over time, following these design principles have resulted in a set of recurring patterns. And these are patterns for how we structure our larger object-oriented designs, and we call those structures design patterns. So you see design principles, they inform and inspire and sit underneath these design patterns. And that's we're going to cover in the rest of the course. But by learning these design principles, you're not only going to improve your everyday object-oriented designs, you're also going to have a leg up on understanding the fundamental principles that underlie design patterns.

Contents