
Simple Factory is one of most used design pattern in Java. It allows interfaces for creating objects without exposing the object creation logic to the client.
Intent
- Creates objects without exposing the instantiation logic to the client.
- Refers to the newly created object through a common interface.
Implementation

The client needs a product, but instead of creating it directly using the new operator, it asks the factory object for a new product, providing the information about the type of object it needs.
|
|
Sometimes, the createProduct() is defined as static. Defining a simple factory as a static method is a common technique and is often called a static factory. Why use a static method? Because you don’t need to instantiate an object to make use of the create method. But remember it also has the disadvantage that you can’t subclass and change the behavior of the create method.




近期评论