Creating a Report Data Model – PriceMatcher

Ok, so I’ve spoken briefly on the subject of separation of concerns in report creation. Let’s now start working through an example.

Pretend I’m starting a new web product — call it (I’ve not done the brief check to see if this exists. This site collects data from local grocery store flyers and stores information on where grocery products are the cheapest in your city.

What information is needed on a site like this? Product, price, store, flyer date. These are just some simple pieces of data that would be required. Let’s lay it out into an XML structure that makes sense for this data:


As you can see, we are tracking the city we’re looking at, a list of prices for that city, the date of the price, the product, and the cost. This is all we need for a simple report. But how do we create an object structure that can easily be turned into that structure?

We have a couple options if we are going to use C# and .Net (right now, I am). We could either make a class implementing System.Linq.Xml and create an actual XML structure. This works ok. Instead, we are going to using System.Xml.Serialization and create a serializable structure. This provides us with a little bit more flexibility and less initial overhead.

Here is the code that will implement the data model:

public class PricingData
    public PricingData()
        Prices = new List<Price>();
    public string City { get; set; }
    public List<Price> Prices { get; set; }

    public class Price
        public DateTime Date { get; set; }

        public string Product { get; set; }

        public double Cost { get; set; }

So, we have a desired data model, and a couple classes that implement that structure. What is the optimal way to utilize these classes? That’s a discussion for another day.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s