Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi,
I change the question, because the previous one did not answer. So, we have the pattern described here:
http://en.wikipedia.org/wiki/Abstract_factory_pattern[^]

Example for my question:

Abstract Factory - interface with the creation of defined opserations for each of the abstract object (eg IWidgetAbstractFactory)
Factories concrete - abstract factory interface implementations (eg GtkFactory, FltkFactory)
Abstract objects - an interface for the type of object (eg IButton, ICheckBox)
Concrete objects - implementation of an abstract object (eg GtkButton, GtkCheckBox, FltkButton, FltkCheckBox)
Client - uses only the abstract factory and abstract object (do not need to know the names of the specific classes).

My question:
What happened when GTK have "triangle button", and Fltk - does not.

Is it possible that factories have not the same objects ?

What should be done in that case ?
Posted
Updated 29-Jun-11 5:35am
v3

I am not sure if I understand your question. Are you saying, that one Factory has a triangle Button (which implements IButton) and the other Factory does not? That would be perfectly valid, only the interface matters. If that was not your question, please reclarify.
 
Share this answer
 
Comments
mnd017 29-Jun-11 15:23pm    
Hi, thx for your replay.
Gkt and Ftlk libraries is only an example. Trinagle Button too. I don't even know it is possible, nvm. It was just an example.

Look at my comment for Solution 2
In this specific case of Trinagle Button, Triangle is the shape a button can have. It is shape aspect of the button you are creating. I think it should be an input to the creation of the button. Looking at the example in wiki, its the paint method that decides how the button to be rendered.

To your question, in case Gtk factory needs something extra that Ftlk factory does not need, the additional need of gtk factory should be part of a separate interface.

GtkFactory would implement both interfaces and FltkFactory would implement IWidgetAbstractFactory interface.
 
Share this answer
 
Comments
mnd017 29-Jun-11 15:21pm    
Hi, thx for your replay.
Gkt and Ftlk libraries is only an example. Trinagle Button too. I don't even know it is possible, nvm.

I'm asking about this specific pattern: Abstract factory.
Factory One - has Product1, Product2 and Product3
Factory Two - has Product1 and Product2

How can i do IFactory interface ?
Morl99 29-Jun-11 16:52pm    
Like Vivek stated, you would have two interface, one that has IProduct1 and IProduct2 in it, and another one which has IProduct3 in it, Factory2 would then implement both interfaces, Factory1 would only implement the first interface. If you want specific help, show us your real problem ;)
mnd017 29-Jun-11 17:09pm    
This is my real problem - I just use "better" example:)
In fact.. this WAS my real problem. Thank you - I created two interfaces and it works.

I just don't know if that is ok with 'Abstract factory pattern'. All I want is create perfect 'Abstract factory' project.
Vivek Krishnamurthy 30-Jun-11 2:28am    
That is Abstract factory pattern. My suggestion was keeping in mind Interface segration principle, which is one of the basic principles of OO design

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900