Factory Method pattern?

Factory Method pattern?

Post by Ing. Jaroslav Bachori » Tue, 20 Jun 2000 04:00:00



Hi,

I'm trying to figure out what is the most appropriate pattern for my design
(I'm very beginner, so, please, be patient).
Let's say I have a product. This product can be movie on film-reel, movie on
video, book etc. Also the product can be aimed for sales, rental or internet
distribution. The products have some attributes common (like title,
synopsis, keywords), some specific to the distribution media (eg. number of
reels, video tape length in minutes etc.) and some depending on whether the
product is to be sold or rented (retail price, rental price, rental period
unit etc.).

Is it proper to use Factory Method to create different instances of a
product with different combination of distribution media and distribution
channel (eg. video-sales, book-sales, video-rental etc.)? I'm rather
confused as the requirements mentioned don't correspond to any pattern in
books directly :(

Thanks for response

            Jaroslav Bachorik

 
 
 

Factory Method pattern?

Post by Wolfgang Kelle » Tue, 20 Jun 2000 04:00:00


Jaroslav,

your problem has been discussed in a paper by Prof.Ralph Johnson of
UIUC:[Joh+98a] Ralph Johnson, Jeff Oakes: The User-Defined Product Framework;

You should be able to find it on the net - otherwise try to get it from Ralph
by mail.

You could also check the Type Object Pattern
Ralph Johnson, Bobby Woolf:  Type Object, in Robert Martin, Dirk Riehle, Frank
Buschmann (Eds.): Pattern Languages of Program Design 3. Addison-Wesley 1998

Cheers

Wolfgang


> Hi,

> I'm trying to figure out what is the most appropriate pattern for my design
> (I'm very beginner, so, please, be patient).
> Let's say I have a product. This product can be movie on film-reel, movie on
> video, book etc. Also the product can be aimed for sales, rental or internet
> distribution. The products have some attributes common (like title,
> synopsis, keywords), some specific to the distribution media (eg. number of
> reels, video tape length in minutes etc.) and some depending on whether the
> product is to be sold or rented (retail price, rental price, rental period
> unit etc.).

> Is it proper to use Factory Method to create different instances of a
> product with different combination of distribution media and distribution
> channel (eg. video-sales, book-sales, video-rental etc.)? I'm rather
> confused as the requirements mentioned don't correspond to any pattern in
> books directly :(

> Thanks for response

>             Jaroslav Bachorik

--
================================================================

Web:   http://www.objectarchitects.de/ObjectArchitects/

 
 
 

Factory Method pattern?

Post by Andy Watso » Wed, 21 Jun 2000 04:00:00


To throw a different light on the subject and help you with your
objects. You might want to look up the MARC record format on the net.
This format is specially designed to handle what you are trying to do.

Perform your analysis on the MARC format and you should find it a bit
easier to design an app.

Andy

On Mon, 19 Jun 2000 08:16:24 GMT, "Ing. Jaroslav Bachorik"


>Hi,

>I'm trying to figure out what is the most appropriate pattern for my design
>(I'm very beginner, so, please, be patient).
>Let's say I have a product. This product can be movie on film-reel, movie on
>video, book etc. Also the product can be aimed for sales, rental or internet
>distribution. The products have some attributes common (like title,
>synopsis, keywords), some specific to the distribution media (eg. number of
>reels, video tape length in minutes etc.) and some depending on whether the
>product is to be sold or rented (retail price, rental price, rental period
>unit etc.).

>Is it proper to use Factory Method to create different instances of a
>product with different combination of distribution media and distribution
>channel (eg. video-sales, book-sales, video-rental etc.)? I'm rather
>confused as the requirements mentioned don't correspond to any pattern in
>books directly :(

>Thanks for response

>            Jaroslav Bachorik

 
 
 

1. Factory methods patterns and parallel hierarchies

In Gamma et. al.(1995)'s "Design patterns: elements of reusable
o-o software", there is a pattern called the "Factory Method"
which deals with parallel hierarchies (Chapter 13).

An example starting on p. 109-110 shows an example of
a Figure hierarchy running parallel with a Manipulator hierarchy.
Subclasses of Figure (e.g. LineFigure and TextFigure) each redefine
a factory method

 virtual Manipulator * CreateManipulator();

which creates a corresponding Manipulator-subclass.
For instance,
 class Figure
 {
  ...
  virtual Manipulator * CreateManipulator()=0; // abstract virtual
 };// end class Figure

 class LineFigure : Figure
 {
  ...
  virtual Manipulator * CreateManipulator()
    {
      ...
      return new LineManipulator;
    };// end inline function LineFigure::CreateManipulator
 };// end class LineFigure

 class TextFigure : Figure
 {
  ...
  virtual Manipulator * CreateManipulator()
   {
     ...
     return new TextManipulator;
   };// end inline function TextFigure::CreateManipulator
  ...
 };// end class TextFigure

When the class Figure and Manipulator can encapsulate alot of the
functionality, this pattern reuses code, and the virtual functions
dynamically bind the correct member functions in LineManipulator
and TextManipulator.

My question is how should the situations where LineFigure or TextFigure
need to deal with specifically LineManipulator or TextManipulator
be handled?  If LineFigure would like to call a
function LineManipulator::F() which is not defined in Manipulator,
the CreateManipulator() will not work since it returns a pointer
to Manipulator instead of the appropriate subclass LineManipulator.

Should LineFigure define another member function
 LineManipulator * CreateLineManipulator();
to get a LineManipulator pointer, and use it to access the
LineManipulator specific function F()?
 ...
 CreateLineManipulator()->F();
 ...

Somehow it feels kludgy, but I can't think of any other ways.
Any suggestions or comments would be welcome.

-Han

2. 4500 Cisco Router config.

3. Differences between Abstract Factory and Factory Method Design Patterns

4. Monitor Size for NextStep?

5. Factory methods and Pattern Languages

6. VT100 keyboard mapping to Sun X server

7. Abstract Factory vs. Factory Method???

8. Client Access message queue

9. Difference between Abstract Factory and Factory Method

10. problem with pluggable factory pattern

11. Factory design pattern

12. factory pattern and access to functions of derived class and dynamic_cast

13. Abstract Factory pattern