This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Abstract Factory need explanation

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need some help in understanding Abstract Factory.
#################################################################
From my understanding, Factory Pattern is the central point of the creation of object that relates to a Base class
e.g.
abstract class Fruit,
class Apple extends Fruit
class Orange extends Fruit
class FruitFactory
public static void getFruit(type para)
{
if (para == x)
return new Apple();
else
return new Orange();
}
client code
Fruit f = FruitFactory.getFruit(para);
In this case, client do have to know if f is apple or orange.
#################################################################
For Abstract Factory,
abstract class House - defines method getChair, getTable
class Hut extends House - implements getChair, getTable
class Apartment extends House - implements getChair, getTable
getChair and getTable will create Chair and Table object accordingly.
Thus, I can use either Hut or Apartment to create Chair and Table object.
However, from the client I'd still need to know whether to create Hut or Apartment.
client
House h = new Hut(); // or new Apartment();
So, in actual case, the client still need to know which object to create as compare to Factory pattern, right?
Does it means that to hide the Abstract Factory from client, I'd need a Factory for the Abstract Factory which means a
HouseFactory, which will create an appropriate Hut or Apartment which then create the Table and Chair.
Whew!
Please comment if I've understand Abstract Factory correctly.
Cheers.


Han Ming
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am sorry, could't read through attentively.
but the exampel u have given is not really an example of abstract factory.
it's actually a method that should be used to create appropriate concretefactories.
pl. see is this helps http://www.ciol.com/content/technology/sw_desg_patt/101061802.asp
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Avijeet Dash:

http://www.ciol.com/content/technology/sw_desg_patt/101061802.asp


There are quite a few inconsistencies in the URL above. In fact, it seems the class diagram and the sample codes are not in sync. I suggest you strictly follow the code to understand.

------------------
Thank you.
- Simon See
simon-ivy@usa.net
-after office hours-
necro-mani-cide
 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the clarification.
I know that I've made the mistake.
And, thanks for the link too.
I'm referring to it now.
Cheers.

Han Ming
 
Avijeet Dash
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just checked it again, and the code and the UML are in sync.
what is not in sync?
thanks again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic