Re: Factory method question
- From: jonathan.broderick@xxxxxxxxx
- Date: Thu, 13 Mar 2008 10:45:47 -0700 (PDT)
On Mar 13, 10:27 am, "Peter Duniho" <NpOeStPe...@xxxxxxxxxxxxxxxx>
wrote:
On Thu, 13 Mar 2008 08:32:59 -0700, <jonathan.broder...@xxxxxxxxx> wrote:
[...]
Is there a way i could do something like this:
IConditional c = ConditionalFactory.Create(<data>);
That way I let the Factory know which object to create and how. I Dont
want to have to do soemthing like this:
IConditional c = ConditionalFactory.CreateField(<data>);
or...
IConditional c = ConditionalFactory.CreateDate(<data>);
The creating part I'm not so sure how to do.
Is "<data>" typed at the point that you'd call that code? Or is it some
generic blob of data? If it's typed, then you just need overloads for the
Create() method for each type. If it's a generic blob of data, you'll
need to turn that into the appropriate type to pass to a constructor,
which you can do inside the Create() method. In fact, this is a typical
use of a factory: having the factory do the data analysis to determine
what type to return.
What that analysis would be depends on your exact situation. Without more
information, it's hard to say how the exact implementation would look.
But there's no fundamental reason you can't do it that way.
Pete
Yes at this point <data> is NOT typed but rather a generic blob of
data. The data would come from a source (like a user or database). I
was imagining it being an associative array of some sort that could
easily be accessed through well known keys.
I was concerned there was a "better" way of doing things but every
example I have seen on Google has only been simple cases. Granted,
"better" is in the eye of the beholder (or application for that
matter) but I want to make sure I'm not learning it one way and one
way only then forcing that pattern upon the problem when another
solution/pattern might be a better fit.
.
- References:
- Factory method question
- From: jonathan . broderick
- Re: Factory method question
- From: Paul E Collins
- Re: Factory method question
- From: jonathan . broderick
- Re: Factory method question
- From: Paul E Collins
- Re: Factory method question
- From: jonathan . broderick
- Re: Factory method question
- From: Peter Duniho
- Factory method question
- Prev by Date: Re: ms sec fix caused SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
- Next by Date: Datasets and Excel
- Previous by thread: Re: Factory method question
- Next by thread: Re: Factory method question
- Index(es):