Skip to content

Apoorv's Blog Posts

Creational Design Pattern: Builder Pattern

Builder pattern fixes few problems that factory or abstract factory pattern has. In previous examples of Factory Patterns we only checked concrete objects that only required an empty constructor but what if there are too many parameters and many of them are variable. This makes using factory or abstract factory difficult because of the huge constructor declarations and dependencies that must be resolved in the perfect order.

Creational Design Pattern: Abstract Factory Pattern

Abstract Factory pattern is an extension of Factory pattern where even the factory is abstracted out. In factory pattern you just Abstract out on the type of object you want to create thus by creating a factory that can provide a similar object set like in our example the Animals in Animal’s kingdom. But what if we need to create multiple objects that our in different subsets. For example, in Animal’s kingdom there are not just animals that can roam, what about Birds, Reptiles or Water Animals? They all cannot be a part of animal set which only implements roam method.

Creational Design Pattern: Factory Pattern

Next up our sleeves is the factory pattern which is yet another and very popular object creation pattern. Factory Method Pattern just define an interface or abstract class for creating an object and a factory class or method will be responsible in creating object that inherited that abstract class or interface. No other class would ever be able to create an object of the class. The class will be self-responsible for the creation of the object. This will decouple the initiation logic.