Re: OO, I just don't get it.

From: Jan Ploski (jpljpl_at_gmx.de)
Date: 12/16/03


Date: Tue, 16 Dec 2003 20:04:59 +0100

Val wrote:
> Is class "MyDocument" really neccessary within the scope of "Factoring
> Methods"? I was thinking like this:
> a) Make an abstract entitiy-creator.
> b) Derrive a concrete entitiy-creator for absstract-creator.
> c) Make THE entity.
> - Regarding "c": This thing is going to be added. The framework supports it,
> but that's obvious. But it shouldn't be relevant whether '' THE entity" is
> derrived from something or not.
>
> Am I right or is a super-class of "THE entity" an inherent aspect to
> "Factoring Methods".? Or in this case, with this code, is "MyDocument" a
> MUST?

They are called "Factory Methods". Factory in the sense of a producer,
not to be confused with "factoring" in the sense of dividing some whole
into pieces.

You ask whether the base class Document and a subclass MyDoucment are
essential to the pattern or if you could get away with just Document. My
opinion is that you could have just one product class and different
subclasses of the factory returning instances created in different ways.
I would still call the makeXXX method a "factory method", especially if
it is pure virtual in the base class. The makeXXX method can be used to
postpone to subclasses *how* the product gets created, not just *what
type* of product gets created, even if that latter use seems more common.

-JPL



Relevant Pages

  • Re: Access subclass attributes from base
    ... factory object with the interface described earlier that implements more than ... The Instance property is the factory method that utilizes ... The subclasses only responsibility is to tell the base class to which ... super-generic base class contain it all. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Access subclass attributes from base
    ... generic factory using an attribute to specify the type of concrete class that will be implemented. ... You seem to have created the problem for yourself by insisting that a super-generic base class contain it all. ... This doesn't actually help the subclasses. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Unification of Methods and Functions
    ... I am suggesting that we write factory methods using classmethod to give ... my classes all implement an interface which I'll call 'shape ... Rectangle and Ellipse have a common base class, ...
    (comp.lang.python)
  • Re: Factory method
    ... The base class must not create the children. ... If you don't want a public constructor, then define a Factory ... >I have an abstract class, and a set of classes that inherit from my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Creating funny objects
    ... a "factory" is used so that the programmer can override it to ... create a subclass of SAXParser. ... I have subclasses called "AdvertisingPlaylist", ... I have a PlaylistFactory with a method ...
    (comp.lang.java.programmer)