Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Class Design

Posted on 2007-07-29
1
Medium Priority
?
210 Views
Last Modified: 2010-04-15
I working on basic ecommerce web site and need some input on the class design for products and items.
The idea is that a product can have different item numbers. The item may have different color, size or price, but still the same product.

I started the products class.
Would I create another class called item?
Let's say I need to access properties from both classes, would I create another class for this or inherit from the other?

My Products database table
ProductID
ProductName
Description
Image

My Items database table
ItemID
ProductID
ItemNumber
Description
Cost
Price

public class Product
{
    private Guid _productID;
    private string _productName;
    private string _description;    
    private string _image;

    public Guid ProductID
    {
        get
        {
            return _productID;
        }
        set
        {
            _productID = value;
        }
    }
   

    public string ProductName
    {
        get
        {
            return _productName;
        }
        set
        {
            _productName = value;
        }
    }

    public string Description
    {
        get
        {
            return _description;
        }
        set
        {
            _description = value;
        }
    }    

    public string Image
    {
        get
        {
            return _image;
        }
        set
        {
            _image = value;
        }
    }
0
Comment
Question by:JRockFL
1 Comment
 
LVL 20

Accepted Solution

by:
REA_ANDREW earned 2000 total points
ID: 19588490
Make another class called Variance perhaps. Then each product can have a Variance.

The Variance class could inherit from the Dictionary Object or simple contain a Dictionary as a member

That way you could say for example

Product prodA = new Product();
ProductVariance p1 = new ProductVariance("Color","Blue");
ProductVariance p2 = new ProductVariance("FaciaStyle","Urban");
prodA.Variances.Add(p1);
prodA.Variances.Add(p2);

Andrew
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question