tags:

views:

75

answers:

3

I have the following layout:

Entities:

Order
OrderItem

DAO classes:

OrderDAO
OrderItemDAO

So I have POCO classes, and DAO classes.

Now I want to encapsulate the above entities into another entity, so I can have methods like:

x.AddItem(OrderItem item)
x.CalculateTotal();
x.CalculateShipping();
x.Charge();

What would this type of entity be called? Factory? Or just a simple wrapper class?

+1  A: 

It will definitely not be a factory (that could be the object that creates your "joint" entity, though). Possibly a wrapper, yes. But why not have the Order entity manage its OrderItems directly by creating a relationship between both?

Romain
+2  A: 

Typically, I divide my code base into several layers: Modeling layer, Data Access layer, Manager/business-logic layer, and UI

In this case, I'd suggest leaving Order/OrderItem POCOs and creating an OrderManager class. It would be a stateless singleton, and have methods like AddItem(Order, OrderItem). Internally, it would deal with the specifics of updating the models, committing data changes, any transactionality, etc.

Aaron
I like the solution. Elegant enough. Though, there is a bit of wondering whether it creates (too) strong coupling between the "manager" class and the DAO layer.
Romain
The DAO layer handles loads/queries/commits and could be handed to the manager during construction by interface (In Java land I use Guice for this kind of injection). I've found that if you've gone at least that far (dependency injection) you don't need to worry about abstracting the interfaces until you really need to, because the abstraction lines are well understood.
Aaron
A: 

Sounds more like a Facade Pattern to me. Hide the actual implementation of the act of doing those various processes. Or in layman terms a wrapper would be correct.

See here: http://en.wikipedia.org/wiki/Facade%5Fpattern

WillMatt