Question regarding proper OO design

H

havremunken

Hi there,

A project I am working on uses an XML-file to store the objects from a
session, plus some metadata and definitions for this session. A brief
explanation follows;

The main class type is the Entry. Entry objects have certain
attributes, methods and properties, and really make up the core of the
application.

There is another class, the RatingCategory, which has some settings,
and a list of Rating objects. These are used for creating user ratings
for each Entry - each Entry object can (but doesn't have to) be rated
in each of the the rating types. An Entry will typically contain a
collection of EntryRating objects, where each EntryRating has a
pointer to the corresponding Rating object, plus the score in that
particular category.

There are also other "top level classes" along with RatingCategory
etc. that are defined in the file.

Now, I want to make a "superclass" which is the DataFile (inventive
name, I know) class. This will be the in-memory representation of the
XML file containing the RatingCategory, Rating, Entry etc. objects. I
want the DataFile class to have methods and properties so I can behave
such as this:

DataFile df = DataFile.Load( string fileName );
df.Entries.Add( new Entry() );
df.Save();

And that is really no problem at all.

However, say that each Entry object will have a Rating property (get
only). This will check all the EntryRating objects, calculate their
values using RatingCategory and Rating objects, and report a 0-100
type integer. However, to be able to do this, the Entry object will
need knowledge of the list of RatingCategory objects that the DataFile
keeps; The same also holds true for other cross-relations inside the
DataFile - the different object types may need to know about each
other (mainly Entry objects needing to know of the others), however,
isn't it clumsy for each Entry object to keep a pointer to the
DataFile it belongs to?

I want to be able to unit test this properly, both on the level of the
DataFile (create a DataFile, save it, load it back, compare the
contents) and the individual objects; I also want the option to keep
several DataFile objects in memory at once (MDI interface), so static
pointers won't do any good either.

What is the correct design decision to make here? Would it be to have
a method in the DataFile/RatingCategory objects like this;

int GetEntryRating(Entry entryToRate);

Or does that violate the single responsibility thingy?

Any ideas here would be welcomed!

Thanks in advance,

Rune
 
D

Devon-S

Rune,

You might want a Typed DataSet. It could load the XML and you would have
access to all of the tables. There is a great tutorial on it by Scott
Mitchell at http://www.asp.net/learn/data-access/?lang=cs

It is an in-memory representation of the data and all of the sub data pieces
at once.

Hope this is helpful,

Devon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top