- Spring 5 Design Patterns
- Dinesh Rajput
- 270字
- 2021-07-08 09:59:30
Factory design pattern
- GOF Design Pattern
The Factory design pattern is a creational design pattern. The Factory design pattern is also known as the Factory method design pattern. According to this design pattern, you get an object of a class without exposing the underlying logic to the client. It assigns a new object to the caller by using a common interface or abstract class. This means that the design pattern hides the actual logic of the implementation of an object, how to create it, and which class to instantiate it in. So the client shouldn't worry about creating, managing, and destroying an object-the Factory pattern takes responsibility for these tasks. The Factory pattern is one of the most-used design patterns in Java.
Let's look at the benefits of the Factory pattern:
- The Factory pattern promotes loose coupling between collaborating components or classes by using interfaces rather than binding application-specific classes into the application code
- Using this pattern, you can get an implementation of an object of classes that implement an interface, at runtime
- The object life cycle is managed by the factory implemented by this pattern
Now let's discuss some common problems where you should apply the Factory design pattern:
- This pattern removes the burden on the developer to create and manage the objects
- This pattern removes the tight coupling between collaboration components because a component doesn't know what subclasses it will be required to create
- Avoid hard code to create an object of the class
- Mastering Adobe Captivate 2017(Fourth Edition)
- PHP基礎案例教程
- Python高級編程
- 大模型RAG實戰:RAG原理、應用與系統構建
- Haskell Data Analysis Cookbook
- C語言程序設計上機指導與習題解答(第2版)
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- 編程菜鳥學Python數據分析
- RealSenseTM互動開發實戰
- Scala Data Analysis Cookbook
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- Android應用開發實戰(第2版)
- 從零開始學Selenium自動化測試:基于Python:視頻教學版
- C語言從入門到精通