K
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.
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.