• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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.
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic