- 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
- Flask Web全棧開發(fā)實(shí)戰(zhàn)
- DevOps:軟件架構(gòu)師行動(dòng)指南
- 國(guó)際大學(xué)生程序設(shè)計(jì)競(jìng)賽中山大學(xué)內(nèi)部選拔真題解(二)
- Vue.js 3.x從入門到精通(視頻教學(xué)版)
- Apache Spark Graph Processing
- 數(shù)據(jù)結(jié)構(gòu)(C語言)
- Learning Python by Building Games
- 西門子S7-200 SMART PLC編程從入門到實(shí)踐
- Julia for Data Science
- 小型編譯器設(shè)計(jì)實(shí)踐
- ExtJS Web應(yīng)用程序開發(fā)指南第2版
- MySQL核心技術(shù)與最佳實(shí)踐
- Java Web入門很輕松(微課超值版)
- JavaScript編程精解(原書第3版)
- Advanced C++