Factory Method
Definition
The Factory pattern provides a way to use an instance as a object factory.
The factory can return an instance of one of several possible classes
(in a subclass hierarchy), depending on the data provided to it.
Where to use
@When a class can't anticipate which kind of class of object it must create.
@You want to localize the knowledge of which class gets created.
@When you have classes that is derived from the same subclasses, or they
may in fact be unrelated classes that just share the same interface. Either
way, the methods in these class instances are the same and can be used
interchangeably.
@When you want to insulate the client from the actual type that is being
instantiated.
The Factory pattern provides a way to use an instance as a object factory.
The factory can return an instance of one of several possible classes
(in a subclass hierarchy), depending on the data provided to it.
Where to use
@When a class can't anticipate which kind of class of object it must create.
@You want to localize the knowledge of which class gets created.
@When you have classes that is derived from the same subclasses, or they
may in fact be unrelated classes that just share the same interface. Either
way, the methods in these class instances are the same and can be used
interchangeably.
@When you want to insulate the client from the actual type that is being
instantiated.
Labels: Design Pattern, Java
0 Comments:
Post a Comment
<< Home