Thursday, May 15, 2014

Factory Method Pattern in Java

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."


Run 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.


Factory method pattern (wiki)

No comments:

Post a Comment