From: Christian Franzen on
Hi!

I'm trying to design a configuration class. At the moment I solve this
problem by extending an interface offering the methods getValue() and
setValue() with concret classes that store the config data either in a
database or xml file or ini file. This concret classes are designed as
singelton (but this doesn't matter). To get an instance of one of this
classes I use a factory-method-class.
I thing this works fine but I dont like this factory-class, because it is
not obvious how to instantiate one of the implementations. So I tried to
combine my config interface and the factory class to an abstract class that
I can use as an "interface" and a factory but im not sure if this will cause
any problems or disadvantages. What do you thing?

mfg Xion

p.s.: I'm sorry for my bad english


From: Daniel Pitts on
On Sep 27, 7:27 am, "Christian Franzen" <christian.fran...(a)rwth-
aachen.de> wrote:
> Hi!
>
> I'm trying to design a configuration class. At the moment I solve this
> problem by extending an interface offering the methods getValue() and
> setValue() with concret classes that store the config data either in a
> database or xml file or ini file. This concret classes are designed as
> singelton (but this doesn't matter). To get an instance of one of this
> classes I use a factory-method-class.
> I thing this works fine but I dont like this factory-class, because it is
> not obvious how to instantiate one of the implementations. So I tried to
> combine my config interface and the factory class to an abstract class that
> I can use as an "interface" and a factory but im not sure if this will cause
> any problems or disadvantages. What do you thing?
>
> mfg Xion
>
> p.s.: I'm sorry for my bad english

My personally philosophy is that code is as malleable as oil. If you
find that it is a problem down the road, refactor. You should start
with the simplest possible solution that fits your situation.
Situations change, but so can your solution.

As for your particular question, you should use polymorphism iff you
can express an "IS A" relationship. Also, it shouldn't matter to
consumers of an object how it was instantiated (look for dependency
injection); All consumers should care about is how the object
interacts with them, or rather how they interact with that object.

From: Ed Kirwan on
Christian Franzen wrote:

> Hi!
>
> I'm trying to design a configuration class. At the moment I solve this
> problem by extending an interface offering the methods getValue() and
> setValue() with concret classes that store the config data either in a
> database or xml file or ini file. This concret classes are designed as
> singelton (but this doesn't matter). To get an instance of one of this
> classes I use a factory-method-class.
> I thing this works fine but I dont like this factory-class, because it is
> not obvious how to instantiate one of the implementations. So I tried to
> combine my config interface and the factory class to an abstract class
> that I can use as an "interface" and a factory but im not sure if this
> will cause any problems or disadvantages. What do you thing?
>
> mfg Xion
>
> p.s.: I'm sorry for my bad english

Can you give us an example of how you use your factory method to instantiate
one of the implementations and why this is not obvious?

I can only give an example of a configuration mechanism I used, even though
yours sounds more industrial than this example.

In this example, a poker game, I have a Configuration object that provides
holds Option objects. Each Option holds various configurable options for
the game, such as the amount to be used for each ante, the amount for a
standard opening bet, etc.

Clients of the Configuration object use a string (or tag) to identify which
particular option implementation they want, for example:

Option anteOption =
configuration.getOption(Configuration.ANTE_OPTION_TAG);
int ante = anteOption.getValue();

I don't consider this particularly unobvious.

For more information, see:
http://www.edmundkirwan.com/servlet/fractal/cs1/frac-cs110.html

--
..ed

www.EdmundKirwan.com - Home of The Fractal Class Composition

From: H. S. Lahman on
Responding to Franzen...

> I'm trying to design a configuration class. At the moment I solve this
> problem by extending an interface offering the methods getValue() and
> setValue() with concret classes that store the config data either in a
> database or xml file or ini file. This concret classes are designed as
> singelton (but this doesn't matter). To get an instance of one of this
> classes I use a factory-method-class.
> I thing this works fine but I dont like this factory-class, because it is
> not obvious how to instantiate one of the implementations. So I tried to
> combine my config interface and the factory class to an abstract class that
> I can use as an "interface" and a factory but im not sure if this will cause
> any problems or disadvantages. What do you thing?

I'm with Kirwan; I don't understand what the problem is.

The behavior method implementations that handle XML, SQL, or whatever
would be defined with the Configuration object, presumably as subclasses
if different persistence mechanisms can be used. All the factory object
does is initialize knowledge attributes, instantiate relationships, and
physically instantiate the right Configuration object.


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl(a)pathfindermda.com
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info(a)pathfindermda.com for your copy.
Pathfinder is hiring:
http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH