OO Design/Coding help

krepunk

Well-Known Member
Joined
Nov 1, 2006
Messages
307
Hi,

I'm busy studying for my uni exams(java) in October and have come across an interesting "problem" that I would like some help with :)

Say you have a hifi store that sells hifi combos. The store has a number of items in stock (different speakers, turntables, cd players, dvd players, etc) and a customer can choose a combo that can contain a number of each stock.
Eg.

Combo 1 = Speaker_1 x 2, CD Player_1 x 1, dvd player_1 x 1)
Combo 2 = Speaker_1 x 4, dvd player_1 x 1, TV_1 x 1)
Combo 3 = Speaker_2 x 2, Speaker_1 x 2, TV_1 x 1)
etc...

So all the different combo's will affect the stock level of an item differently when purchased.
The store must keep track of stock levels of each item so that it can reorder when it is low on stock.
I originally thought then that I would have 3 classes, Order, Combo, and StockItem.
Each combo class containing an array of stock items as well as an array which specifies how many of each item is needed in the combo.
Is this the best way to do this?
Actually I first thought that I could keep the number of items in a combo in the actual StockItem class, but then each combo uses a different number of that Item.
Is this the best way to do this? With 2 arrays in the Combo class I mean.
Could I create a new class called ComboItem maybe that contains a StockItem, and also the number of Items in that Combo. So a Combo would contain an array of ComboItems?
But then is it possible to have multiple ComboItems that contain the same StockItem?

I would think it probably be best to look at using a database with all the combos and stock items in tables, but we haven't done database connectivity in the course yet so I'm thinking it's not an option. Besides, not every pc has an Oracle or SQL installed inorder to use database functionality.

What would be the best way to design these classes and their relationships without using a database?

Any hints or advice would be great :)
 

Loop

Active Member
Joined
Sep 4, 2007
Messages
50
is the application gonna be web based or not, because if it is the user wont need the database on his pc since it is hosted on the server.

To be honoust tho I cant see how an application like this could have real world feasablility without some sort of database
 

Shred

Expert Member
Company Rep
Joined
Jul 12, 2006
Messages
1,736
Well, since you are not using a database, here is my opinion on the classes

class Combo
{
ComboItem[] ComboItems
}

class ComboItem
{
Product
Quatity
}

class Product
{

}

You should then validate that a user cannot create another combo item for a product that has already been used.

You can then write a method on the Combo class to return you a list of products and quanitties.

Hope that helps.
 

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
is the application gonna be web based or not, because if it is the user wont need the database on his pc since it is hosted on the server.

To be honoust tho I cant see how an application like this could have real world feasablility without some sort of database

This is an academic question, very typical of Software Engineering/OO Design.

Anyway onto the problem:
I'd do it something like this (forgive the bad naming convention):

Code:
class StockItem
    string Description
    double UnitPrice

class ComboItem
    StockItem SItem;
    int Quantity;

class ComboItemCollection
    List<ComboItem> CItems

class Combo
   ComboItemCollection CCItems;
   double ComboPrice;

You could then iterate through Combo.CCItems to find each combo item -> stock item and its quantity.
 

krepunk

Well-Known Member
Joined
Nov 1, 2006
Messages
307
Code:
class StockItem
    string Description
    double UnitPrice

class ComboItem
    StockItem SItem;
    int Quantity;

class ComboItemCollection
    List<ComboItem> CItems

class Combo
   ComboItemCollection CCItems;
   double ComboPrice;
You could then iterate through Combo.CCItems to find each combo item -> stock item and its quantity.

Thanks for all the replies guys :)
This is what I thought would work, just wanted to check that there isn't something I'm not thinking about.
I'll try it out on the weekend and see if it works.
 
Top