Skip to content

bzdgn/gang-of-four-design-patterns-in-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gang Of Four Design Patterns In Java


I'm uploading this project to git in order to self learning and recap my design patterns knowledge. Design patterns are needed to make good practice and generalized design solutions for the known programming design problems. This project is about famous Gang Of Four Design Patterns and their implementation examples in Java.


Creational Design Patterns

Structural Design Patterns

Behavioral Design Patterns


Design Patterns Notes

A - Creational Design Patterns

    1. Singleton

         Intro

         Singleton guarantees only one instance of the class is going to be created. It guarantees the control of a resource. Singleton is a creational design pattern thus the instantiation of the class is controlled by the implementation of this pattern. It is usually lazily loaded. Singleton is responsible for creating itself and managing its own lifecycle. It is static in nature but it is not implemented using a static class typically. Because in order to make the implementation thread-safe, it is not build-up with static class. The constructor of the singleton is private so that other than the class itself, no other class can call the constructor of the Singleton class. And the reference to the class instance, which can only be only unique per runtime environment, is also stored as private so that only the class itself can reach and control its lifecycle. Also notify that there are no parameters in the private constructor and if there should be, it violates the rules of Singleton. If you require parameters to create an instance of a class, you should prefer or you need a factory pattern.

         Examples

         Java Runtime Environment, Logger, Spring Beans(they are Singleton's by default), Graphics Managers

         Pros and Cons

         xxxxxxxxxxxx

         Dummy

         xxxxxxxxxxxx

    2. Builder

    3. Prototype

    4. Factory

    5. Abstract Factory