School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,464 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,685 people online right now. Registration is fast and FREE... Join Now!




Class Design

 

Class Design

scalt

28 Jun, 2009 - 03:17 PM
Post #1

D.I.C Head
Group Icon

Joined: 22 Nov, 2007
Posts: 196



Thanked: 23 times
Dream Kudos: 25
My Contributions
Hi

I have to come up with a series of classes for holding information in the background of a GUI application I am creating. The application is to help farm systems modellers to create simulations which will be run through a 3rd party application.

Basically what the user does is define a bunch Factors (ie Fertiliser Application, Rainfall, Stocking Rate for arguments sake), then set up some Values for each Factor. After this they create Simulations which consist of a combination of different Factor Values

So I guess you could represent it like this (assuming we have 4 classes, Experiment, Factor, Value and Simulation):

- An Experiment consists of 1 to many Factors and 1 to many Simulations
- A Factor consists of 1 to many Values
- A Simulation consists of 1 to many *Factor Values* (MUST have every Factor, and ONE Value for each Factor)

My question is, what is the best way of representing *Factor Values*?
If I was to do this the way I usually do I would create a data structure that would hold the indexes of a Factor and Value (assuming Factors were stored in an array in Experiment, and Values were stored in an array in Factor), then simply put an array of that data structure inside Simulation. Is this correct from an object-oriented design point of view?

Factor is primarily an attribute of Experiment, Simulation just references it so we can get the values out for generating the file to run through the simulation software.

Any ideas/advice would be great (and if this is in the wrong topic then can a mod please move it)

User is offlineProfile CardPM
+Quote Post


Oler1s

RE: Class Design

28 Jun, 2009 - 03:24 PM
Post #2

D.I.C Addict
****

Joined: 4 Jun, 2009
Posts: 639



Thanked: 66 times
My Contributions
QUOTE
If I was to do this the way I usually do I would create a data structure that would hold the indexes of a Factor and Value (assuming Factors were stored in an array in Experiment, and Values were stored in an array in Factor)
Sounds a bit convoluted and too coupled. Why not just store a structure of Factors (e.g. an array of Factors). Each factor type is responsible for how it stores values.

QUOTE
Is this correct from an object-oriented design point of view?
Correctness is hard to define. But people can take potshots at an idea and you can see how many problems are flagged. In other words, how much does an idea smell? Your mechanism sounds a bit fishy already to me.

EDIT: Also to note, there isn't much to note on OO. It's more of just general design and approach. Storing indices and the like sounds a bit convoluted.

This post has been edited by Oler1s: 28 Jun, 2009 - 03:25 PM
User is offlineProfile CardPM
+Quote Post

scalt

RE: Class Design

28 Jun, 2009 - 03:44 PM
Post #3

D.I.C Head
Group Icon

Joined: 22 Nov, 2007
Posts: 196



Thanked: 23 times
Dream Kudos: 25
My Contributions
Thanks, that sounds like a good idea.
User is offlineProfile CardPM
+Quote Post

Aeternalis

RE: Class Design

21 Jul, 2009 - 02:16 PM
Post #4

D.I.C Regular
***

Joined: 13 Jul, 2009
Posts: 261



Thanked: 25 times
My Contributions
A good method of implementing one to many relationships in OO programming is to implement a vector of the type of (the many side) objects in the (one side) class. So if you had a factor class that could contain 1 to many value types you would put a vector of value types inside the factor class.

Using C++ and the STL here. Other implementations would be similar.

Aet
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:28AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month