aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes abstract factory - object composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "abstract factory - object composition" Watch "abstract factory - object composition" New topic
Author

abstract factory - object composition

nibla jose
Greenhorn

Joined: May 25, 2009
Posts: 28
I have heard, factory uses inheritance and abstract factory uses object composition to do their job. Factory using inheritance is somewhat obvious. What about object composition by abstract factory? How does it use object composition?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I don't see it, either. Perhaps that statement was wrong, or misunderstood?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
nibla jose
Greenhorn

Joined: May 25, 2009
Posts: 28
Read it in head first design patterns.. No idea what they meant...
Bugged me..
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Can you quote the relevant passage from the book?
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
I don't know what they are talking about.

The most common way to implement abstract factory is using factory method pattern.
The main different is abstract factory is used for creating families of products.

I think the pattern name should be "Families of Products Factory", many people don't understand this pattern partly because of its undescriptive name.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Ivan Pig
Greenhorn

Joined: Jun 28, 2009
Posts: 2
Kengkaj Sathianpantarit wrote:I don't know what they are talking about.

The most common way to implement abstract factory is using factory method pattern.
The main different is abstract factory is used for creating families of products.

I think the pattern name should be "Families of Products Factory", many people don't understand this pattern partly because of its undescriptive name.


I used to be confused by the names and the explains by GOF....
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Kengkaj Sathianpantarit wrote:
I think the pattern name should be "Families of Products Factory", many people don't understand this pattern partly because of its undescriptive name.


But that's not really a description of the pattern, but just of one of the most common uses...
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Ilja Preuss wrote:
Kengkaj Sathianpantarit wrote:
I think the pattern name should be "Families of Products Factory", many people don't understand this pattern partly because of its undescriptive name.


But that's not really a description of the pattern, but just of one of the most common uses...

"Families" is the most important part of the description of this pattern.

From GoF:
Intent
Provide an interface for creating families of related or dependent objects without specifying their
concrete classes.


I don't understand why they named this pattern Abstract Factory.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Kengkaj Sathianpantarit wrote:
"Families" is the most important part of the description of this pattern.


I don't see why it would be.

You could easily create a class with just static creation methods that creates a family of related objects. Take the Object Mother pattern as an example. Those are not Abstract Factories.


I don't understand why they named this pattern Abstract Factory.


Because the pattern consists of an abstract base class/interface, and a number of concrete implementations. Clients only know about the abstract base class - the "abstract factory".
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Ilja Preuss wrote:
Kengkaj Sathianpantarit wrote:
"Families" is the most important part of the description of this pattern.


I don't see why it would be.

You could easily create a class with just static creation methods that creates a family of related objects. Take the Object Mother pattern as an example. Those are not Abstract Factories.

You can read GoF. They mentions families or means that not only in Intent section, but also in Motivation, Applicability, Consequences, and Implementations.
We can create family of products using another way, but that doesn't mean Abstract Factory doesn't create family of products.

Ilja Preuss wrote:

I don't understand why they named this pattern Abstract Factory.


Because the pattern consists of an abstract base class/interface, and a number of concrete implementations. Clients only know about the abstract base class - the "abstract factory".

This reason is very weak to me. In that case why don't we prefix other patterns with "abstract"? Like Abstract Builder, Abstract Command, Abstract Composite, Abstract Strategy?

Most of design patterns use program to interface.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Kengkaj Sathianpantarit wrote:
Ilja Preuss wrote:
Kengkaj Sathianpantarit wrote:
"Families" is the most important part of the description of this pattern.


I don't see why it would be.

You could easily create a class with just static creation methods that creates a family of related objects. Take the Object Mother pattern as an example. Those are not Abstract Factories.

You can read GoF. They mentions families or means that not only in Intent section, but also in Motivation, Applicability, Consequences, and Implementations.


I don't see how that necessarily makes it the most important part of the description.


We can create family of products using another way, but that doesn't mean Abstract Factory doesn't create family of products.


Did I imply that it doesn't?


Ilja Preuss wrote:

I don't understand why they named this pattern Abstract Factory.


Because the pattern consists of an abstract base class/interface, and a number of concrete implementations. Clients only know about the abstract base class - the "abstract factory".

This reason is very weak to me. In that case why don't we prefix other patterns with "abstract"? Like Abstract Builder, Abstract Command, Abstract Composite, Abstract Strategy?


Good question. I guess just "Factory" wasn't discriminate enough in the presence of Factory Method.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Ilja Preuss wrote:
Kengkaj Sathianpantarit wrote:
Ilja Preuss wrote:
Kengkaj Sathianpantarit wrote:
"Families" is the most important part of the description of this pattern.


I don't see why it would be.

You could easily create a class with just static creation methods that creates a family of related objects. Take the Object Mother pattern as an example. Those are not Abstract Factories.

You can read GoF. They mentions families or means that not only in Intent section, but also in Motivation, Applicability, Consequences, and Implementations.


I don't see how that necessarily makes it the most important part of the description.

Let's analysis together then.
From Intent from GoF.
Intent
Provide an interface for creating families of related or dependent objects without specifying their
concrete classes.

Which part do you think it's the most important?
1. "Provide an interface for"
2. "creating families of related or dependent objects"
3. "without specifying their concrete classes."

1. and 3. are also important but that just does imply program to interface. For me core of this pattern is 2.

Anyway, did you know that if we want to use an interface to create something (not family), we can just use Factory Method?
We use Abstract Factory if we want to create families of objects, if not create families, Factory Method is enough, Abstract Factory classes are often implemented with Factory Method pattern after all.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Kengkaj Sathianpantarit wrote:
From Intent from GoF.
Intent
Provide an interface for creating families of related or dependent objects without specifying their
concrete classes.

Which part do you think it's the most important?
1. "Provide an interface for"
2. "creating families of related or dependent objects"
3. "without specifying their concrete classes."

1. and 3. are also important but that just does imply program to interface. For me core of this pattern is 2.


Well, this is a *design* pattern, so it's not only the intent that is relevant, but also the design that is used to realize the intent. After all, there can be more than one design to realize an intent, and they would be different patterns.

Also, I don't agree with the implication that "program to interface" is less important to this pattern than the rest of the intent. In fact, it's exactly the ability to be able to *exchange* factories for one another without any changes to the clients that is at the core of this pattern.

Anyway, did you know that if we want to use an interface to create something (not family), we can just use Factory Method?


Or Prototype. Or probably one of a couple of different (non-GoF) patterns. All with slightly different forces on the surrounding design, of course. And sometimes you will still want to use Abstract Factory, won't you?
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Ilja Preuss wrote:
Anyway, did you know that if we want to use an interface to create something (not family), we can just use Factory Method?


Or Prototype. Or probably one of a couple of different (non-GoF) patterns. All with slightly different forces on the surrounding design, of course. And sometimes you will still want to use Abstract Factory, won't you?

I won't. Because Abstract Factory is for creating families of products.
Anyway, let's end this discussion, because I don't think it would go anywhere .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract factory - object composition