Re: Factory Class Question

From: Jason MacKenzie (jmackenzie_nospamallowed_at_formet.com)
Date: 12/06/04


Date: Mon, 6 Dec 2004 14:57:43 -0500

Jay - thanks for the response.

Here is what I have right now:

I have a base class called Employee

I have 2 derived classes based on Employee called Facilty1_Employee and
Facilty2_Employee

I have a factory class that has a function that returns Employee and will
instatiate Facility1 or 2 depending on a setting in the registry.

Facility2_Employee has an overloaded constructor which means I can't make it
private (as far as I know).

Facilty1_employee takes one argument in its constructor as well which means
I can't make that private.

Should I be setting properties instead of using passing arguments to the
constructors to accomplish what I'm trying to do?

Thanks a million,

Jason MacKenzie

"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:ON73Sq82EHA.1292@TK2MSFTNGP10.phx.gbl...
> Jason,
> The "easiest" way is to make the constructor private which will only allow
> the class itself to create an instance.
>
> This unfortunately will not prevent creating an instance via reflection &
> Activator.CreateInstance... Using Activator.CreateInstance to create an
> instance of a class with a private constructor is rare, however it is
> possible.
>
> Hope this helps
> Jay
>
> "Jason MacKenzie" <jmackenzie_nospamallowed@formet.com> wrote in message
> news:e$8hiR82EHA.1192@tk2msftngp13.phx.gbl...
>> Is there a way to prevent classes from being instantiated by methods
>> other than my factory pattern?
>>
>> I have a couple of classes and want to force the factory class to be used
>> as the "entry point".
>>
>> Any help is appreciated,
>>
>> Jason MacKenzie
>>
>
>



Relevant Pages

  • Re: Questions about cruise experience
    ... Jay wrote: ... So I'm supposed to assume that every employee is underpaid and needs ... me to supplement his income?? ... might be tempted to avoid that "cultural more" of paying tax on their ...
    (rec.travel.cruises)
  • Re: Factory Class Question
    ... move EmployeeFactory, Employee, Facilty1Employee, and Facilty2Employee all ... Facilty1Employee, and Facilty2Employee as Friend. ... > Facility2_Employee has an overloaded constructor which means I can't make ... >> instance of a class with a private constructor is rare, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Can this Class be cleaned up at all?
    ... less than 8 significant digits. ... All I need to do is change the way that the initialSalary is defined in the Employee class and the other classes that extend it should be easy to retrofit. ... That means that every class that extends employee and creates a new employee will have to have the call to the constructor changed. ...
    (comp.lang.java.help)
  • Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
    ... No, but imagine a better example that uses a slightly better name, like ... where I have a class representing Employees. ... asking for a new employee, i.e. a new thing of a certain kind. ... my constructor can be called anything: ...
    (comp.lang.perl.misc)
  • Re: classes, strings, learning in VS.NET
    ... > It is a good Compiler, ... > Here you declare that you will provide a constructor for your Employee ...
    (comp.lang.cpp)