473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

OO Design Question

Kay
Hello,
My question isn't specific to .Net but as .Net is object oriented, I would
be interested if someone could let me know if there is a standard way of
implementing what I describe below in OO or if it is covered by a design
pattern. I hope someone can help me as I have been looking for a solution to
this question for a while.

For example:

If I have a number of Customers and each Customer can have a number of
Orders associated with them, each Order can have a number of Products
associated with it. To implement this in OO, I would have the following
classes :
Customer,
Order and
Product
(1) If I want to retrieve all the Orders for a customer, should I have an
arraylist of Order objects within the Customer class and similarly have an
arraylist of Product objects within the Order Class?
When I instantiate the Customer class, should I get all the Orders
associated with the Customer and fill the arraylist of Order objects? I.e.
at the time of instantiating a Customer getting all the Orders and Products
for the Customer or should I provide a method such as GetAllOrders in the
Customer class that is called when you require the Orders associated with
the Customer.
(2) If I needed to display in a dropdown list, all the Customer Names, is
this another class or how do I implement it i.e. I need a method that
returns a list of Client names, to what class would this belong to?. I asume
it is not good practice to return a dataset or datareader to the code behind
of a web page. This question applies to lists of anything, for e.g. I might
want to display in a dropdown list, all the order numbers associated with a
client.

(3) Another common task might be to sum the total of each order, in what
class would this be implemented.
Your help would be much appreciated.

Thanks in advance,
Kay.
Jul 21 '05 #1
6 1290
Hi Kay,

Although I can't really help you with some of your specific questions I have
some experience of OR (Object/Relational) mapping. There is a good example
of how relational schemas can be translated into object mappings :
http://www.ormapper.net/Examples/?ID=IntroSchema . I hope at least the
examples can point you in the right direction.

BTW We have used this OR Mapper in a recent project and I can highly
recommend it.
"Kay" wrote:
Hello,
My question isn't specific to .Net but as .Net is object oriented, I would
be interested if someone could let me know if there is a standard way of
implementing what I describe below in OO or if it is covered by a design
pattern. I hope someone can help me as I have been looking for a solution to
this question for a while.

For example:

If I have a number of Customers and each Customer can have a number of
Orders associated with them, each Order can have a number of Products
associated with it. To implement this in OO, I would have the following
classes :
Customer,
Order and
Product
(1) If I want to retrieve all the Orders for a customer, should I have an
arraylist of Order objects within the Customer class and similarly have an
arraylist of Product objects within the Order Class?
When I instantiate the Customer class, should I get all the Orders
associated with the Customer and fill the arraylist of Order objects? I.e.
at the time of instantiating a Customer getting all the Orders and Products
for the Customer or should I provide a method such as GetAllOrders in the
Customer class that is called when you require the Orders associated with
the Customer.
(2) If I needed to display in a dropdown list, all the Customer Names, is
this another class or how do I implement it i.e. I need a method that
returns a list of Client names, to what class would this belong to?. I asume
it is not good practice to return a dataset or datareader to the code behind
of a web page. This question applies to lists of anything, for e.g. I might
want to display in a dropdown list, all the order numbers associated with a
client.

(3) Another common task might be to sum the total of each order, in what
class would this be implemented.
Your help would be much appreciated.

Thanks in advance,
Kay.

Jul 21 '05 #2
"Kay" <ka********@proteus.ie> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,
My question isn't specific to .Net but as .Net is object oriented, I would
be interested if someone could let me know if there is a standard way of
implementing what I describe below in OO or if it is covered by a design
pattern. I hope someone can help me as I have been looking for a solution
to
this question for a while.

For example:

If I have a number of Customers and each Customer can have a number of
Orders associated with them, each Order can have a number of Products
associated with it. To implement this in OO, I would have the following
classes :
Customer,
Order and
Product

These are the right classes.

(1) If I want to retrieve all the Orders for a customer, should I have an
arraylist of Order objects within the Customer class and similarly have an
arraylist of Product objects within the Order Class?
When I instantiate the Customer class, should I get all the Orders
associated with the Customer and fill the arraylist of Order objects? I.e.
at the time of instantiating a Customer getting all the Orders and
Products
for the Customer or should I provide a method such as GetAllOrders in the
Customer class that is called when you require the Orders associated with
the Customer.

I would not load these at time of instantiating, you never know how many
orders there are, thus this can take a while. You should know when the
order are required (when a user selects this Customer from your drop-down
for instance). I would implement that as follows (this is c# syntax):

public class Customer
{
private ArrayList alOrders = null;

// Now add a property to your class
public ArrayList Orders
{
get
{
if (alOrder == null)
{
alOrders = // LOAD THE ORDERS
}
return alOrders;
}
}
}

This would ensure that when you access the Orders property the first time,
the list will be populated.

(2) If I needed to display in a dropdown list, all the Customer Names, is
this another class or how do I implement it i.e. I need a method that
returns a list of Client names, to what class would this belong to?. I
asume
it is not good practice to return a dataset or datareader to the code
behind
of a web page. This question applies to lists of anything, for e.g. I
might
want to display in a dropdown list, all the order numbers associated with
a
client.
For this you'll need another class, i.e. some sort of Customer Collection.
This class will hold a list of Customer objects (you could use an arraylist
again). To get the list of Customer Names, you can scroll through the list
of customers and return a list of their names.

As for the second part of the question, regarding a list of Orders per
Customer; this can be implemented in the Customer class.


(3) Another common task might be to sum the total of each order, in what
class would this be implemented.
You should add a property or method to your Order class that returns it's
total. Then in the Customer class you can have a method that scrolls
through all the Orders and sums their total.



Your help would be much appreciated.

Thanks in advance,
Kay.

Hope this helps!
Jul 21 '05 #3
Kay,

I would not do it the way you do.

I always ask. To what does something belong

A Client belongs to the company
Does an order belong to the Client, in my opinion not, it is related to the
Client and belongs to the company. Is the product(row) from the client, no
it is related to the order.

Client
has a collection of references too order objects
Orders
has a reference too a Client
has a collection (class) Ordered Productrows with a reference in it to
the Product object
Product
can have a collection of references too productrows

Just my thought,

Cor
Jul 21 '05 #4
I agree with Cor.

The big benefit to using collections is you can modify your collection
member class (Order, a member of the Orders collection) with minimal impact
on the rest of your object hierarchy. Your Orders collection object will
always consist of Order objects.

You can then take it a step further, if you want to derive different Order
types (say, a CustomerOrder versus a CorporateOrder), and still preserve the
integrity of your collection members (since CustomerOrder and CorporateOrder
derive from base class Order).

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OX*************@TK2MSFTNGP15.phx.gbl...
Kay,

I would not do it the way you do.

I always ask. To what does something belong

A Client belongs to the company
Does an order belong to the Client, in my opinion not, it is related to the Client and belongs to the company. Is the product(row) from the client, no it is related to the order.

Client
has a collection of references too order objects
Orders
has a reference too a Client
has a collection (class) Ordered Productrows with a reference in it to
the Product object
Product
can have a collection of references too productrows

Just my thought,

Cor

Jul 21 '05 #5
Kay
Thanks everyone for your response.

Cor,

Maybe I have misunderstood what you have said below, I was suggesting 3
classes, Customer, Order and Product.

The customer class has a collection of references to Order objects as you
said below.

The Order class has a collection of references to Product objects and as
you said below has a reference to a Client. I am not sure what is meant by
"Orders has a collection (class) Ordered Productrows with a reference in it
to the Product object", is this different to, Orders has a collection of
references to Product objects?

In my example I was thinking that a Product Class would just contain
information about the product such as name of Product, description etc.

I was thinging of a very simple situation i.e. a database with a Customer
Table no foreign keys, an Order table with a foreign key Customer Id and
Product Id and a Product table with no foreign keys.

Thanks,

Kay.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OX*************@TK2MSFTNGP15.phx.gbl...
Kay,

I would not do it the way you do.

I always ask. To what does something belong

A Client belongs to the company
Does an order belong to the Client, in my opinion not, it is related to the Client and belongs to the company. Is the product(row) from the client, no it is related to the order.

Client
has a collection of references too order objects
Orders
has a reference too a Client
has a collection (class) Ordered Productrows with a reference in it to
the Product object
Product
can have a collection of references too productrows

Just my thought,

Cor

Jul 21 '05 #6
Kay,

I did assume that an order could contains more products and with that maybe
special information for that product about the delivery.

The base of that information is than the product object of course.

Said in another way.

An order has an order description and orderrows, what I named productrows.
(What is not everywhere necessary).

Cor
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
2
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.