gang-of-4-patterns AT lists.siebelschool.illinois.edu
Subject: Design Patterns discussion
List archive
- From: Ray Ye <rayye AT Catena.com>
- To: "'Jacob George'" <jacobg AT atinav.com>, GOF Mailing List <gang-of-4-patterns AT cs.uiuc.edu>
- Subject: RE: [gang-of-4-patterns] Doubt on creational patterns..
- Date: Mon, 22 Sep 2003 09:25:31 -0400
- List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
- List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>
Hi
Jacob,
Think
this way, factory method is also called "abstract constructor", it is a method
on super class, and the subclass is supposed to override this method to return a
concrete implementation. e.g.,
you
have a class called AbstractDocument
public
class AbstractDocument implements Document {
public abstract Document
createDocument();
...
}
since
the AbstractDocument has no idea what kind of document the subclass is going to
create, so it leaves it as an abstract method, if you have a real document to
realize, you can have,
public
class MyDocument extends AbstractDocument {
public Document createDocument() {
return this;
}
...
}
In
this sense, it is categorized as "Class creational pattern", because the
subclass has to provide the implementation. Remember, AbstractDocument is not a
factory, it is a class which has a "factory method".
On the
other hand, a factory class may be composed of a lot of factory methods to
create a family of products. I will still use the above example but tweak it a
bit,
public
interface DocumentFactory {
public Header createHeader();
public Footer createFooter();
public Content createContent();
}
Now
you have different types of documents(headers, footers, contents) to
create, and you can use abstract factory to control their types, since for the
same type of document, its header, footer and content have to be
compatible.
public
MsDocumentFactory implements DocumentFactory {
...
}
public
AdobeDocumentFactory implements DocumentFactory {
...
}
You
have different factories to create different families of document. Somewhere in
you application, you have to determine which factory to plug in, and there are a
lot ways to do that, e.g., you have use config files, or application
parameters.
Hope
this helps,
Cheers,
Ray
-----Original Message-----
From: Jacob George [mailto:jacobg AT atinav.com] Sent: Monday, September 22, 2003 5:00 AM To: GOF Mailing List Subject: [gang-of-4-patterns] Doubt on creational patterns.. Hi,
I am new to this
group and is presently trying to understand creational patterns. I got confused
by the "Factory method" pattern and "Abstract Factory" pattern. Both are used
for instantiating objects, right? But one is class creational while other is
object creational; this point I doesn't understand clearly.
Factory method
pattern defers the creation of objects to its sub-classes; anyway, in a actual
scenario there will be one concrete factory for creating required objects,
right? This is same in the case of Abstract Factory also. So how can we call one
as class creational while other as object creational? In both the cases, the
type of objects created by the factory changes only by using a factory
sub-class, isn't it so?
I have read the
respective chapters repeatedly, but was confused on reading "Factory method"
& "Abstract factory". Somebody please help me clear the confusion.
ThankYou.
regards
Jacob
George
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.520 / Virus Database: 318 - Release Date: 9/18/2003 |
- [gang-of-4-patterns] Doubt on creational patterns.., Jacob George, 09/22/2003
- <Possible follow-up(s)>
- RE: [gang-of-4-patterns] Doubt on creational patterns.., mgrand AT mindspring.com, 09/22/2003
- RE: [gang-of-4-patterns] Doubt on creational patterns.., sanjeev_s, 09/22/2003
- Re: [gang-of-4-patterns] Doubt on creational patterns.., Jacob George, 09/22/2003
- RE: [gang-of-4-patterns] Doubt on creational patterns.., Ilja Preuß, 09/23/2003
- RE : [gang-of-4-patterns] Doubt on creational patterns.., Mikal Ziane, 09/23/2003
- RE: [gang-of-4-patterns] Doubt on creational patterns.., Ilja Preuß, 09/23/2003
- RE: [gang-of-4-patterns] Doubt on creational patterns.., Ray Ye, 09/22/2003
Archive powered by MHonArc 2.6.16.