“A design pattern is a general reusable solution to a common occurring problem within given context in software design.” (Wikipedia, Software_design_pattern)
Design patterns aren’t completed solutions…they are more like templates that can be used to solve problems and help to organize code. There are three main categories of design patterns: creational, behavioral, and structural. Within these three categories there is a variety of design patterns.
Types of Patterns
- Factory (simplified)
- Factory Method
- Abstract factory
- Object Pool
- Chain of responsibility
- Template method
- Null object
The most common design pattern that I come in the most contact with is the observer pattern from the behavioral category. The observer pattern is used in the model view controller (MVC) architectural pattern. This pattern is used to decouple the model from the view. MVC is often used in swing (JAVA) and .net development for events management. MVC is also commonly used in Php frameworks. The majority of frameworks including Codeigniter, FuelPHP, Larvel, and just about every Php framework use this design pattern.
JAVA Design Patterns
For the conclusion of this research I will try to discuss some of the more commonly used patterns in JAVA. One pattern that is commonly used in JAVA is the Singleton pattern. The Singleton pattern is used to encapsulate the creation of an object in order to maintain control over it. This allows lazy instantiation and ensures that only one object is created. One example of when this is used is for a remote database connection.
Another commonly used pattern is the Factory Method pattern. This pattern is used when it must be decided at run time which one of several compatible classes is to be instantiated. This pattern is used throughout the Java API. A prime example of this pattern being used is the collator class’s getInstance() method which returns a collation object.
Although I only covered some of the basic Creational patterns used in JAVA there are many other patterns used in JAVA development. Design patterns are a valuable tool for OOP design for a number of reasons. They provide a solution to a problem in a context while providing a vocabulary for discussing OOP design at a significant level of abstraction and they serve as a glossary of idioms that will assist in understanding common complex solutions to design problems.Tweet It. Share It.