Take a look at "Head First Design Patterns." This book really helps me
understand patterns. Starting with the "gang of four" book is hopeless.
I think maybe you need nothing more complex than basic factory methods:
* You'll have an interface (in the general sense) for each of the four
types of classes. An abstract class or an interface (per se) I suppose.
* A factory class for each interface. That is the StepFactory, for
example, can instantiate any Step concrete class.
* A concrete class for each subtype that inherits or implements (as
appropriate) it's general interface.
So some omnipotent code will instantiate a RequestFactory, for example,
and pass parameters the RequestFactory.CreateRequest(...) method, let's
say. The question then becomes, does this "omnipotent" code create all
the collections via factories and assemble the parts or Does the
Request have a Step factory and a Step has a QuestionSet factory and so
on.
If the latter, then an instantiated Request will have a StepFactory and
the Request must have enough info in it to know what kind of Step(s) to
tell the factory to make. If not then perhaps the "omnipotent" code
creates it all.
Is this anything like you are thinking?
On 2006-11-16 01:10:31 -0600, "chanmm" <ch*****@hotmail.comsaid:
The easy way to solve this as I see you need to do some drawing on
either UML or using VSTS. Then it is easy for you to se what Pattern
fit you.
http://msdn.microsoft.com/practices
chanmm
"Sean Chambers" <dk****@gmail.comwrote in message
news:11*********************@m7g2000cwm.googlegrou ps.com...
>Hello,
I feel that there is a cleaner way to accomplish what I am trying to
do.
I have 4 different types of classes:
-Request
--Step
---QuestionSet
----Question
That is the hierarchy chain, one request has multiple steps, one step
has multiple questionsets and one questionset has multiple questions
At the moment, I am creating each collection of objects from its
parents ctor. This just feels sloppy and is becoming very hard to read.
I feel like I can use a pattern here. I was thinking an abstract
factory but I guess I just can't see how it would be used here.
Depending on certain variables in Request will determine which Step
objects to build, and which questionSets to add to the steps. A
QuestionSet will always load all of it's questions, but every other
object will have conditional building.
Can anyone point me in the right direction? Like I said, It works as it
is now, but I am trying to refactor to be more elegant because I don't
like my current solution.
Thanks
Sean