S
Scott Stark
Hello,
I'm just getting started in OOP programming so please forgive the question
if it's a bit basic. I'm trying to wrap my head around the basic principles
of OOP design methodologies and think that if someone can explain the
following, it might help me a bit.
Let's say I have four classes for an e-commerce website: a class named
Customer, which contains a collection of Order objects (the orders they have
placed) which in turn contains a collection of OrderItem objects, which in
turn contains a reference to an individual Product object (or an object that
inherits from the base class Product).
Can someone explain to me how best to design this? My specific questions
are:
1) What is the best way to contain the list of, say, Orders in the Customer
class? A generic collection?
2) Which classes need to implement IEnumerable and IEnumerator in order to
loop through them?
3) Where would I place a function called GetCustomers which returns a list
of all my available Customer objects?
4) What if I wanted customers whose first name was John?
5) If I wanted to be able to do something like
Dim NewCustomer As Customer = New Customer
NewCustomer.FirstName = "John"
NewCustomer.Save()
Where the Save() method persists the data to a database, is that the
appropriate way to do it?
6) What if I wanted a function GetOrderItems(ByVal OrderID As Integer) to
get a collection of OrderItems for a particular order number? Where would
this function be placed? I guess my thought is that it would be a member of
the Order class, but is that the best place for it or is there another
accepted way to do this?
I think you probably get the idea of where my confusion lies. I don't need
code examples of how to actually IMPLEMENT this functionality, I just need
class definitions and the method signatures so I can see where everything
should go, what types should be used (for the collections), etc.
Any help would be very much appreciated.
Thank you,
Scott
I'm just getting started in OOP programming so please forgive the question
if it's a bit basic. I'm trying to wrap my head around the basic principles
of OOP design methodologies and think that if someone can explain the
following, it might help me a bit.
Let's say I have four classes for an e-commerce website: a class named
Customer, which contains a collection of Order objects (the orders they have
placed) which in turn contains a collection of OrderItem objects, which in
turn contains a reference to an individual Product object (or an object that
inherits from the base class Product).
Can someone explain to me how best to design this? My specific questions
are:
1) What is the best way to contain the list of, say, Orders in the Customer
class? A generic collection?
2) Which classes need to implement IEnumerable and IEnumerator in order to
loop through them?
3) Where would I place a function called GetCustomers which returns a list
of all my available Customer objects?
4) What if I wanted customers whose first name was John?
5) If I wanted to be able to do something like
Dim NewCustomer As Customer = New Customer
NewCustomer.FirstName = "John"
NewCustomer.Save()
Where the Save() method persists the data to a database, is that the
appropriate way to do it?
6) What if I wanted a function GetOrderItems(ByVal OrderID As Integer) to
get a collection of OrderItems for a particular order number? Where would
this function be placed? I guess my thought is that it would be a member of
the Order class, but is that the best place for it or is there another
accepted way to do this?
I think you probably get the idea of where my confusion lies. I don't need
code examples of how to actually IMPLEMENT this functionality, I just need
class definitions and the method signatures so I can see where everything
should go, what types should be used (for the collections), etc.
Any help would be very much appreciated.
Thank you,
Scott