Design Patterns
A design pattern is a general solution that can be used to solve commonly occurring problems in software design. A design pattern cannot be put directly into code, rather it is a template of how to solve a problem that can be used various situations.
Design patterns are helpful as they speed up the development process by providing proven examples to be used as a reference for common problems. When designing software, small subtle issues can build up leading to major problems that can only be seen during implementation. Using design patterns can help prevent these subtle issues from occurring which reduces the likelihood of major issues occurring.
Because design patterns are tested, proven, and commonly used, patterns also allows for better communication among developers by using well known and understood names for software interactions.
Types of Design Patterns
Creational
Creational design patterns cover class instantiation. These patterns can be further divided into two classifications, class-creation and object-creational patterns. Class creation uses inheritance in the instantiation process, while object creation uses delegation to create objects. Some creational design patterns are:
- Singleton
- A class where only a single instance can exist
- Factory Method
- Creates an instance of several derived classes
- Object Pool
- Avoids expensive acquisition and release of resources by recycling objects that are no longer in use
Structural
Structural design patterns are about class and object composition. Like creational patterns, structural patterns can also be broken down into class creation and structural object patterns. Class creation patterns use inheritance to compose interfaces, while object patterns define ways to compose objects to obtain new functionality. Some structural patterns are:
- Adapter
- Matches interfaces of different classes
- Private Class Data
- Restricts accessor/mutator method access
- Decorator
- Adds responsibility to objects dynamically
Behavior
Behavior design patterns are about how objects communicate with each other. Some examples of behavior design patterns are:
- Null Object
- Used to act as a default value of an object
- Chain of Responsibility
- A way of passing a request between a chain of objects
- State
- Alter an object’s behavior when its state changes
Conclusion
This article was chosen because it clearly described what design patterns are, what they are used for, and gave examples of the different types of design patterns. As stated before, not only does the usage of design patterns help with preventing major issues, they also allow for better communication among developers which is essential to a team’s success which is why I chose to write about design patterns. As I continue to design software, effectively using design patterns will become more and more prevalent, so learning about them now will only be beneficial.
Resources:
https://sourcemaking.com/design_patterns
From the blog CS@Worcester – Zack's CS Blog by ztram1 and used with permission of the author. All other rights reserved by the author.