Design Patterns – Factory Method



The Factory Method as defined: “Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses“. The main point of using this design pattern is to use an interface to hide the class and use an abstract factory method (from an inherited abstract or concrete class) to create composition of the actual class.

Download the source sample: here

Basically, I created a schedule object that will generate a family schedule. We have an interface class to impose the factory method. Then an Abstract Class to hide the actual initialization of the derived class.
if looked carefully. We can see that once we initialize the Concrete Class – it calls the Abstract Class constructor that defers the process of constructing to the createSchedule() method. This brings more security to our code in terms of the creation of the concrete class, we can use this pattern to create objects that has commonality in terms of its composition (common interface / abstract class).

7 thoughts on “Design Patterns – Factory Method

  1. Hi, I am really glad I\\\’ve found this information. A greatblog with exciting content, that\\\’s what I need. Thanks for making this web-site, and I will be visiting again. Have a good day !

  2. Amazing article. I desire you up-to-date your blog significantly more often, I just cannot seem to be to acquire adequate of your blog. I preserved your blog in my bookmarks. Would it be feasible to do a guest post sometime?…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s