views:

55

answers:

2

I'm working on a model for a simple fishing competition and I have some issues with my design.

The main class for the fishing game is Capture and it looks like this:

public class Capture : Entity {

    public virtual int Weight { get; set; }
    public virtual int Length { get; set; }
    public virtual DateTime DateForCapture { get; set; }

    public virtual User CapturedBy { get; set; }
    public virtual Species Species { get; set; }
}

So far there´s no problem but I'm not really sure how to model the game.

  • Every Species is connected to a reference weight that changes from year to year
  • The number of point for a capture is its Weight divided by the current reference weight for the species.

One way to solve the problem is to connect a capture to SpeciesReferenceWeight instead of Species

public class SpeciesReferenceWeight : Entity
{
    public virtual Species Species { get; set; }
    public virtual int ReferenceWeight { get; set; }
    public virtual int Year { get; set; }
}

But in that way that Capture is connected to the implementation details of the game and from my point of view a capture is still a capture even if it's not included in a game.

The result I'm aiming for is like: http://hornalen.net/fishbonkern/2007/ that I wrote a couple of years ago with brute force sql and no domain model.

I would be very happy for all kinds of feeback on this issue.

A: 

Sounds like there're some missing entities. You talk about a game and captures that might be part of a game or not. To get you started you could introduce the entity GameCapture.

public class GameCapture : Entity
{
    public virtual Capture { get; set; }
    public virtual SpeciesReferenceWeight { get; set; }
}

You probably need a Game class as well.

Dala
A: 

If you study Fowler's patterns for things that changes with time (i.e. reference weight), I think you'll find a solution.

Martin R-L
I'm pretty sure this is a possible solution and I'll give it a try. I think that the querying will be the hardest part to solve but I'll guess it's possible to solve it with nhibernates computed properties?
orjan