Design Patterns – Abstract Factory


By Definition, Abstract Factory is “Provide an interface for creating families of related or dependent objects without specifying their concrete classes.“. This simply means that this design pattern is made to hide the actual derived class and create a new layer (or wrapper) that will create the actual instance of this classes. The groupings of classes will be based on their relationship and commonality among its features.

I create a Java code that will showcase the design patterns benefit. The example I made is based on a real world scenario where person types are created for the factory business that needs them.

Download the code: here

 

Checking at the code. The PeopleFactory is an abstract “wrapper” class created to host the creation of Person Objects. As seen, the PeopleFactory provides the layer of security as it hides the actual class implementation / initialization.

My Cent: Abstract Factory do protect the actual implementation / derived class by encapsulating from the other layers of the application. Yet It does have one disadvantage in terms of flexibility: Its made of an abstract class. As every developer should know, abstract class are also extensions of derived class – inheritance of a derived class. OOP only supports single inheritance and that makes the actual factory class not flexible enough.

What do you think is the best replacement for an Abstract class in this case?

5 thoughts on “Design Patterns – Abstract Factory

  1. I’m honored to receive a call coming from a friend immediately he found out the important recommendations shared on the site. Studying your blog post is a real amazing experience. Many thanks for taking into account readers just like me, and I wish you the best of achievements as being a professional realm.

  2. Thanks for the writeup. I definitely agree with what you are saying. I have been talking about this subject a lot lately with my father so hopefully this will get him to see my point of view. Fingers crossed!

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