Posts

5. Prototypes Design Pattern

Prototypes Design Pattern - Prototype pattern is one of the Creational Design patterns, so it provides a mechanism of object creation. However, Prototype pattern is used when the Object creation is a costly affair. Also, it requires a lot of time and resources and if you have a similar object already existing. Therefore, this pattern provides a mechanism to copy the original object to a new object and then modify it according to our needs. Moreover, this pattern uses java cloning to copy the object. - The concept is to copy an existing object rather than creating a new instance from scratch.bcoz creating new object may be constly. - This approach saves costly resource and time, especially when object creation is a heavy process. - Imagine you have an object, let's call it "Prototype". This object is quite complex, and you want to make copies of it, but creating each copy from scratch would be inefficient and time-consuming. So, instead of creating copies by re-creatin...

4. Builder Design Pattern

 Builder Design Pattern      The intent of the Builder Pattern is to separate the construction of a complex object from its representation, so that the same construction process can create different representations. This type of separation reduces the object size. The design turns out to be more modular with each implementation contained in a different builder object. Therefore, Adding a new implementation (i.e., adding a new builder) becomes easier. Furthermore, the object construction process becomes independent of the components that make up the object. This provides more control over the object construction process. - The Builder Design Pattern is a creational pattern used in software design to construct a complex object step by step.  - It allows the construction of a product in a step-by-step fashion, where the construction process can vary based on the type of product being built.  - The pattern separates the construction of a complex object from...

3. Abstract Factory Pattern

Abstract Factory Pattern  - Almost similar to Factory Pattern, except the fact that it’s more like factory of factories. If you are familiar with factory design pattern in java, you will notice that we have a single Factory class that returns the different sub-classes based on the input provided.  - Generally,  factory class uses if-else or switch-case statement to achieve this. However, in Abstract Factory pattern, we get rid of if-else block and have a factory class for each sub-class and then an Abstract Factory class that will return the sub-class, based on the input factory class. - In fact, An abstract factory is a factory that returns factories. Why is this layer of abstraction useful? A normal factory can be used to create sets of related objects. An abstract factory returns factories. Hence, an abstract factory is used to return factories that can be used to create sets of related objects. -  The Abstract Factory Pattern is a way of organizing how you cr...

2. Factory Design Pattern (Creational types)

  Factory Design Pattern  - The Factory design pattern is used when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-classes. This pattern takes out the responsibility of instantiation of a class from a client program to the factory class.  - Super class in factory pattern can either be an interface, or an abstract class, or a normal Java class. - The Factory Design Pattern is one of the creational design patterns and a powerful tool for managing object creation in a flexible and organized way, particularly when an application needs to support multiple variations or types of objects. -  When there is superclass and multiple subclass and we want to get object of subclasses based on input and requirement. -  Then we create factory class which takes reposibility of creating of class based on input. Advantages of Factory Desing pattern 1. focus on creating object for interface rather than implementation. 2....

1. Singleton Design Pattern (Creational types )

Singleton pattern  What is a Singleton Design Pattern? There are only two points in the definition of a singleton design pattern, 1) There should be only one instance allowed for a class and 2) We should allow global point of access to that single instance.  - Singleton pattern will insure that only one instance of the class will be created by java virtual machine at any point of time.  - It is used to provide global point of access to the object.Singleton patterns are used in logging, caches, thread pools,getting device driver objects etc. Steps for Singleton Implementation   1. private constructors :  if it public then we can create multiple object (Constructor use to initialize of object) 2. Static Instance: - we create static instance varible for holds the instance of the class. - Within the Singleton class, there is a static member variable that holds the single instance of the class. 3. public static method : this method allow to other classes to accc...

Introduction Design Pattern

Image
- The design pattern is an essential element in object-oriented programming. - It is a software infrastructure made up of a small number of classes that is used to solve a technical problem. Why these Design Patterns named as GoF? It was 21 October 1994, when four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, with a foreword by Grady Booch, published a book titled as Design Patterns – Elements of Reusable Object-Oriented Software which launched the concept of Design Pattern in Software design. These four authors are altogether known as the Gang of Four (GoF). Since then, these are called GoF Design Patterns.   What are Design Patterns? - A design pattern is a generic repeatable solution to a frequently occurring problem in software design that is used in software engineering. - The design pattern is a reusable solution to a common problem that occurs in software design. Why use a design pattern? - The design pattern can accelerate the development process. It ...