• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Importance of abstract factory pattern

 
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reading up on abstract factory pattern here, and I am not able to completely grasp its importance.

From what I can understand, it allows programmer to not specify instantiating the specific class. So, if there is a DocumentCreator factory and I need to create my resume then I wouldn't need to do this:

DocumentCreator creator = new ResumeCreator();

Instead I can do this with:

DocumentCreator creator = DocumentCreator.getInstance(resume); (I recall)

Does my understanding on this pattern correct and if it is not could you elaborate on its pros? Why is not specifying the concrete class such a big deal?

Also is the GOF book an easy read for someone newly acquainted with design pattern?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The goal is to separate *what* is being done from *how* it is being done. In other words, the code that uses the Abstract Factory only cares about getting a reference to something that is capable of doing something; how that thing is created is irrelevant. This has to do with the concept of coupling. You want your program components to be loosely coupled as opposed to being tightly coupled. Consider the following code:

The latter declaration of myList is tightly coupled to a specific implementation (ArrayList) whereas the former is not. The former is only concerned with the general behavior as defined by the List interface. This same principle is behind the Abstract Factory pattern. The benefit is that it makes your design/code less brittle/more flexible.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really appreciate your explaining in plain and simple language. Thanks a bunch! I suppose the static factory is a close cousin of this pattern and understanding this will speed up comprehending the factory method pattern.
 
Greenhorn
Posts: 3
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I saw that there was no reply to your question "Is the GOF book easy to read?".

Well, of course it depends on what you call "easy to read". The Gof book is strong, but perhaps not the most easy resource for learning about design patterns. The book covers every aspect of the patterns it describes. So it's a very good book if you have already a fair bit of design experience and it can be used as a reference.


I personally prefer Sourcemaking if you want to get a clear overview of the patterns.
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic