Simple Note
(From wiki):
The essence of this pattern is to "Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses."
Program
https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/JAVA/DesignPattern/src/factory/factorymethod
Run TestMain.java to test.
abstract class Audience has a method enjoy, will get a Player to play something then enjoy.
the abstract method getPlayer can be overridden by subclass to provide different Player as needed.
Reference:
Factory method pattern (wiki)
No comments:
Post a Comment