473,414 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Complex hierarchy

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

Nov 15 '06 #1
3 1451
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

Nov 16 '06 #2
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

Nov 17 '06 #3
Hi Sean.. Basically you can use public constructors as you are doing or
static
factory methods with a GetInstance method and private constructors. The
factory lets you return null.

More at: Effective Java Programming Language Guide by Joshua Bloch,
Addison-
Wessley, 2001, 252 pp.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marc te Vruchte | last post by:
Over the past years i've been in contact with the same problem a number of times, creating a graphical user interface on complex XML documents. Personally these solutions have never been...
2
by: Matt | last post by:
Hello, I would like to generate what I call an "overall class hierarchy" in UML automatically derived from my C++ code source. An example of what I seek: ...
4
by: Robert W. | last post by:
I'm thinking of building a complex data model with a number of nested classes but need to know something first. To simplify my question, let me present you this sample data model MainClass...
3
by: Dennis M | last post by:
Hey everyone, I am curious what the performance impact of a custom control would be if it had a significant hierarchy of children. For example, 40 child controls, 5 levels deep, each control on...
2
by: JEB | last post by:
I have an object that wrote the serialization for to use with Remoting and now I would like to use it with Web Services. The object consist of a short and a string value (lets call it Item). This...
4
by: George Sakkis | last post by:
I'd like to gather advice and links to any existing solutions (e.g. libraries, frameworks, design patterns) on general ways of writing complex web forms, as opposed to the typical {name:value} flat...
0
by: Craig Buchanan | last post by:
I was hoping to serial a complex class that i use for plugin management to the web.config file. the object hierarchy is PluginManager Plugins Plugin Tables Table XsltTransformations...
3
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this...
0
by: Suppi | last post by:
Hi all, we're doing a lot of xml/java (de)serialization and thus have defined a bigger type hierarchy in xml-schema. It starts with basic complex type as base classes. These are extended via...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.