0

I'm trying to model the domain of my system but I've come across and issue and could do with some help.

My issue is one of perspective. I'm modeling a system where I have a Customer entity which will have a number of Order entities and the system will be required to list all the Orders for a selected Customer (perspective 1). I therefore modeled a Customer class which contains a collection of Orders... simple. However I've just realised that the system will also need to list all Orders with the details of the Customer (perspective 2) which would mean that I had a single Customer reference from each Order.

The problem is that from each perspective I will be taking time to create object which I will not be interested in E.g. When I will display a list of Orders a Customer instance will be created for each order; in turn the Customer instance will then hold a collection of Orders they have made (which from this perspective I'm not interested in!!).

Could anybody help with suggestions? I've come across this issue before but I've never taken the time to design a proper solution.

Regards,

JLove

raven-king
  • 1,550
  • 2
  • 18
  • 40

1 Answers1

2

I have seen this before. The trick is to differentiate between Customer-Identity and Customer-Details (e.g. Orders). You can then link from all Order-Objects to the Customer-Identity-Object, and in the other view link from the Customer-Identity-Object to the Customer-Details-Object which further links to Order-Objects (you probably want this ordered chronologically).

The implementation can be held as on Object-System or as a relational Database (in which case you would have a table "Customers" with CustomerID as Key, their addresses etc; and a table "Orders" with OrderID as key, and CustomerID as another column.

Bernd Elkemann
  • 23,242
  • 4
  • 37
  • 66
  • I think that may well have been my solution to it in the past. I think I had a base class which just contained the basic details i.e. a customer's identity attributes and then extended this to provide a derived class which had a customer's orders. I was just concered that this wasn't the best approach to the problem. I think perhaps looking into Domain Driven Development might be on the cards... I believe the perspective problem is referred to as a Bounded Context. There's always so much more to learn :-) Thanks! – raven-king Feb 20 '11 at 21:29
  • Yea, the difficulty was to let-go of the class-hierarchy focused subclassing viewpoint and model links instead of inheritance. In an object-oriented language you can model this by having a single Customer-Class (no inheritance) with the 2 fields "ID" and "orders" (orders is of type Array/Vector/List/OrderedCollection depending on the language). An Order-Object has a link to a Client-Object. You can then implement **Views** by separate render-methods in Customer and Order: Customer>>render() prints the Customer-ID and all Orders, Order>>render() prints the order and only the Customer-ID. – Bernd Elkemann Feb 20 '11 at 21:48