If a problem occurs over and over again, a solution to that problem has been used effectively. That solution is described as a pattern. The design patterns are language independent strategies for solving common object-oriented design problems. When you design a software, you should know the names of some common solutions. GOF (Gang Of Four) came up with the solution to common problems called as “Design Patterns”.
If you want to be a professional Java developer, you should know at least some popular solutions to coding problems. Such solutions have been proved efficient and effective by the experienced developers.These solutions are described as so-called design patterns. Learning design patterns speeds up your experience accumulation in OOA/OOD. Once you grasped them, you would be benefitted from them for all your life and jump up yourselves to be a master of designing and developing.
Many programmers with many years’ experience don’t know design patterns, but as an Object-Oriented programmer, you should know them well, especially for new Java programmers. Actually, when you solved a coding problem, you have used a design pattern. You may not use a popular name to describe it or may not choose an effective way to better intellectually control over what you built. Learning how the experienced developers solve the coding problems and trying to use them in your project is a best way to earn your experience and certification.
Remember that learning the design patterns will really change how you design your code; not only you will be smarter but sound a lot smarter, too. The 23 design patterns by GOF are well known, and more are to be discovered on the way.
We will go through three types of patterns as below –
Creational design patterns provide solution to instantiate an object in the best possible way for specific situations. Following design patterns come under this category –
Also code for all examples is available on GitHub on below link –
Structural patterns provide different ways to create a class structure, for example using inheritance and composition to create a large object from small objects. Following design patterns come under this category.
- Adapter Pattern
- Composite Pattern
- Proxy Pattern
- Facade Pattern
- Bridge Pattern
- Decorator Pattern
- Flyweight Pattern
Behavioral patterns provide solution for the better interaction between objects and how to provide lose coupling and flexibility to extend easily. Following design patterns come under this category –