The main difference between factory and facade design pattern is that the factory design pattern is a creational design pattern that defines an interface or an abstract class to create an object, while the facade design pattern is a structural design pattern that provides a simplified interface to represent a set of interfaces in a subsystem to hide its complexity from the client.
A design pattern is a proved solution to solve a particular problem. They are independent of the programming language. In other words, a design pattern does not provide the implementation. However, understanding design patterns helps to develop the software easily. Moreover, they improve reusability, maintainability and flexibility. Two main types of design patterns are creational and structural design pattern. Creational design patterns focus on the method of creating objects. On the other hand, structural design patterns focus on connecting classes and objects to create a larger structure. In overall, the factory is a creational design pattern, while the facade is a structural design pattern.
Key Areas Covered
1. What is a Factory Design Pattern
-Definition, Functionality
2. What is a Facade Design Pattern
-Definition, Functionality
3. Difference Between Factory and Facade Design Pattern
-Comparison of Key Differences
Key Terms
Creational Design Pattern, Facade Design Pattern, Factory Design Pattern, Structural Design Pattern, Virtual Constructor
What is a Factory Design Pattern
Factory design pattern defines an interface or an abstract class to create objects. However, the subclasses of that interface or abstract class decide on creating the objects. In other words, the subclasses create the instances of the class. Factory pattern is also called the factory method pattern or the virtual constructor.
Factory pattern provides mainly two advantages. Firstly, it allows the subclasses to select the type of objects to create. Secondly, it provides loose coupling. In other words, it prevents the requirement to bind the application-specific classes into code. Therefore, the code interacts only with the resultant interface or the abstract class.
It is possible to use the factory design pattern when the class does not know what subclasses are required and when the parent classes select creating the objects for the subclasses.
What is a Facade Design Pattern
A facade design pattern provides a unified and simplified interface to a set of interfaces in a subsystem. It results in hiding the complexity of the subsystem from the client. In other words, this pattern provides a high-level interface so that it is easier to use the subsystem.
Mainly, there are two advantages of the facade design pattern. It avoids the complexity of the subsystem. Secondly, it provides loose coupling among the subsystem and its clients. Furthermore, it is possible to use the facade design pattern when the programmer wants to create a simple interface to a complex subsystem. Additionally, programmers can use this pattern when there are multiple dependencies between the clients and the implementation classes.
Difference Between Factory and Facade Design Pattern
Definition
A factory design pattern is a creational design pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. In contrast, the facade design pattern is a structural design pattern that serves as a front-facing interface masking more complex underlying or structural code. Thus, this is the main difference between factory and facade design pattern.
Type
A factory design pattern is a creational design pattern, while the facade design pattern is a structural design pattern.
Main Advantage
Moreover, the factory design pattern allows the subclasses to select the type of objects to create, whereas the facade design protects the client from the complexity of the subsystem components.
Conclusion
A design pattern provides solutions to solve tasks. When the programmer faces a task, he can use a suitable design pattern to solve the problem quickly and efficiently. There are various design patterns, and two of them are creational and structural design patterns. The factory is an example of a creational pattern, while the facade is an example of a structural design pattern. The main difference between factory and facade design pattern is that factory is a creational design pattern that defines an interface or an abstract class to create an object, while the facade is a structural design pattern that provides a simplified interface to represent a set of interfaces in a subsystem to hide its complexity from the client.
References:
1.“Factory Method Design Pattern – Javatpoint.” Www.javatpoint.com, Available here.
2.“Facade Pattern – Javatpoint.” Www.javatpoint.com, Available here.
3.“Facade Pattern.” Wikipedia, Wikimedia Foundation, 4 July 2019, Available here.
4.“Factory Method Pattern.” Wikipedia, Wikimedia Foundation, 25 June 2019, Available here.
Image Courtesy:
1.”4280758″ via Pixabay
Leave a Reply