Now, you might be asking, “What are design patterns? What do they do?” Design patterns are recurring problems that occur repeatedly in our code. They describe the problem itself and then the main solution. This solution can be applied repeatedly and will always remain a valid solution. Think of design patterns as blueprints for your coding journey. OO design patterns, otherwise known as object-oriented design patterns, help you organize and show the relationship between classes and objects. There are currently three different types of OO design patterns: creational, structural, and behavioral.
These design patterns go over how to create new objects. Usually, object creation is rather simple. However, as our code becomes more advanced, creating objects can become more complicated as well. Some design patterns that fall under the Creation category include: the Factory Method, Abstract Factory, Builder, Prototype, and Singleton. Each of these design patterns solves problems and allows object creation to be managed in a flexible and reusable way.
Design patterns of this type strive to represent and organize classes and objects in a way that allows the code to be maintainable and understandable. In the same way as other design patterns. Structural design patterns mainly solve problems when code becomes more advanced and complicated. They fit each part together without modifying the parts themselves. Some structural design patterns include: Adapter (class and object), Bridge, Composite, Decorator, Facade, Flyweight, and Proxy.
These patterns define how objects communicate and work together. They assist in delegating tasks, iterating, and executing commands. This prevents code from becoming unpredictable and harder to debug. Some behavioral design patterns include: Interpreter, the Template Method, Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, and Visitor.
In my ICS 314 group project, we decided to create a student marketplace for students to sell their old possessions. Even without knowing what a design pattern was at the time, we still managed to apply it to our code self-consciously. We used a shared database connection, which followed a similar pattern to the Singleton pattern. Our notifications feature also acts like an Observer system by automatically reacting when something is changed.
Overall, design patterns allow us programmers to create cleaner and more functional programs. As shown from my group project, the application of design patterns allowed my team to better handle object creation, utilize our UI, and manage our database. As our project, as well as other projects from other programmers across the world, grow in complexity, design patterns are always there as a solid blueprint for each one of us to follow to success.