This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract factory - object composition

 
nibla jose
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see it, either. Perhaps that statement was wrong, or misunderstood?
 
nibla jose
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read it in head first design patterns.. No idea what they meant...
Bugged me..
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you quote the relevant passage from the book?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ivan Pig
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic