A
anonymous.user0
Using the dotnet v1.1 framework (so no generics possible). I'd like to
create a bunch of Factory classes that all inherit from a single
abstract base Factory class. Each Factory is responsible for the
creation of objects of a type that inherit from a base class. Factory
is probably the wrong word here, as it's really a persistance class,
but the problem is the same.
Example:
abstract BaseClass
abstract BaseFactory, uses BaseClasses internally, has a bunch of
abstract and virtual methods that are responsible for the actual
implementation:
virtual BaseClass createNew(); //does a bunch of stuff and calls
doCreateNew() to do actual creation
abstract BaseClass doCreateNew();
virtual bool save(BaseClass b); //does a bunch of stuff and calls
doSave() to actually save
abstract bool doSave(BaseClass b);
...
you get the idea.
concrete ClassA extends BaseClass.
concrete ClassAFactory extends BaseFactory, implements doCreateNew,
doSave, etc. Problem is, I'd like this class to only accept instances
of ClassA rather than BaseClass, and I'd like the createNew functions
to return instances of ClassA rather than BaseClass. I know I can use
new on the functions, but that doesn't seem like the right answer as it
doesn't really hide the base functions.
In fact, the problem is a bit deeper then this, as ClassAFactory itself
can require different parameters for the createNew, save, etc.
functions (such as a userId for auditing purposes), and I would like to
truely hide the base functions (current idea is to implement them and
just throw NotImplemented exceptions, but that seems ugly, and it
clutters up my build logs with a bunch of unreachable code detected
messages)
Anyone have any ideas how this type of thing could be / should be done?
create a bunch of Factory classes that all inherit from a single
abstract base Factory class. Each Factory is responsible for the
creation of objects of a type that inherit from a base class. Factory
is probably the wrong word here, as it's really a persistance class,
but the problem is the same.
Example:
abstract BaseClass
abstract BaseFactory, uses BaseClasses internally, has a bunch of
abstract and virtual methods that are responsible for the actual
implementation:
virtual BaseClass createNew(); //does a bunch of stuff and calls
doCreateNew() to do actual creation
abstract BaseClass doCreateNew();
virtual bool save(BaseClass b); //does a bunch of stuff and calls
doSave() to actually save
abstract bool doSave(BaseClass b);
...
you get the idea.
concrete ClassA extends BaseClass.
concrete ClassAFactory extends BaseFactory, implements doCreateNew,
doSave, etc. Problem is, I'd like this class to only accept instances
of ClassA rather than BaseClass, and I'd like the createNew functions
to return instances of ClassA rather than BaseClass. I know I can use
new on the functions, but that doesn't seem like the right answer as it
doesn't really hide the base functions.
In fact, the problem is a bit deeper then this, as ClassAFactory itself
can require different parameters for the createNew, save, etc.
functions (such as a userId for auditing purposes), and I would like to
truely hide the base functions (current idea is to implement them and
just throw NotImplemented exceptions, but that seems ugly, and it
clutters up my build logs with a bunch of unreachable code detected
messages)
Anyone have any ideas how this type of thing could be / should be done?