Re: Factory method



check out the definition here

http://www.dofactory.com/Patterns/PatternAbstract.aspx


--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.

"Mark" <Mark@xxxxxxxxxxx> wrote in message
news:uQz4Cf0RFHA.2348@xxxxxxxxxxxxxxxxxxxxxxx
> I have an abstract class, and a set of classes that inherit from my
abstract
> class. The fact that it is abstract is likely irrelevant. I have a static
> factory method in my abstract class that creates subclasses. The
> constructor in my subclasses must be able to call the constructor in my
base
> class. For the factory method in my abstract class to call the
constructor
> on my subclasses, the constructor in the subclass MUST be public (or
> internal). They cannot be private or protected. However, doen't that
> basically defeat the purpose of factory? I'd love to be able to make all
> these constructors private or similar so that someone can't create
subclass
> instances without using the Factory. If this was all in a separate DLL, I
> suppose I'd be saved by "internal", but we have small team of developers
> working on projects where that type of seperation really shouldn't be
> necessary.
>
> Suggestions? Code sample below ...
>
> Thanks in advance.
>
> Mark
>
>
> public abstract class MyBase
> {
> protected string first;
>
> public MyBase(string first )
> {
> this.first = first;
> }
>
> public static MyBase Factory(int stateId)
> {
> switch (stateId)
> {
> case 700:
> return new MySubClass1(first);
> default:
> throw new Exception("Bogus code!");
> }
> }
> }
>
>


.



Relevant Pages

  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: abstract constructor performance?
    ... > the performance hit of the call to the abstract constructor under load. ... my code creates about 200 instances of the subclasses ... If the abstract class has no constructor, then there's no call to it? ... The call itself has a negligible performance penalty - if performance was a ...
    (comp.lang.java.programmer)
  • Re: Creating funny objects
    ... > I have always been taught to creat object in the form ... Basically, it's more flexible than a constructor, because a constructor ... code, SAXParser is an abstract class, so it's not possible to instantiate ... The factory method will use "new" in some way, ...
    (comp.lang.java.programmer)
  • Factory method
    ... I have an abstract class, and a set of classes that inherit from my abstract ... factory method in my abstract class that creates subclasses. ... constructor in my subclasses must be able to call the constructor in my base ... For the factory method in my abstract class to call the constructor ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Overridden methods
    ... >> overriding method then do some common functionality. ... Programs don't use instances of an abstract class, ... subclasses. ... transmitted without the written permission of the copyright owner. ...
    (perl.beginners)