The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Deleting BLL object. Design question

I have a silly question that is bugging me for some time (about 2 or 3 hours):

Say I have this BLL class (let's say BLL_Order ) that can be used, refrenced, whatever, by other classes (say BLL_OrderItem via a OrderID property). Enough to be said that deleting the BLL_Order w/out deleting all the aferent BLL_OrderItems would be a bad thing.

How whould you go about designing the "Can I Delete This Order" part.

1. Have BLL_Order publish a cancelable event "CanIBeDeleted" that anyone interested can subscribe to and refuse the Delete action, and take appropiate action?

2. Have the BLL_Order search for it's order items, and refuse to be deleted if order items are still present?

3. Have a 3rd Mediator class that handles all these BLL class relationships with a public method CanThisObjectBeDeleted(object obj) ?

Well, in my example things were oversimplified, but in real case I have a bunch of these dependencies from one object to antother (and sometimes recursive within a class ), so I guess I'm asking what system would be more flexible and easier to manage?
Radu094 Send private email
Thursday, April 24, 2008
The Order class should be responsible for the lifecycle of its OrderItem instances. What's BLL mean?
John Topley Send private email
Thursday, April 24, 2008
sorry, BLL = I meant as Business Logic Layer
Radu094 Send private email
Thursday, April 24, 2008
You could always make the BLL_Order.Delete() function delete all associated BLL_OrderItems as well.

Or you could design it so that if any BLL_OrderItems exist, the BLL_Order.Delete() won't delete anything and return FALSE (or some sort of error code) to tell the caller of the problem.
Brian Shipe Send private email
Thursday, April 24, 2008
Depending on your platform, there's probably a framework of some sort that could help.  In .Net, for instance, you could look at Rocky Lhotka's CSLA framework, which is all about getting business objects to behave during maneuvers like this.  I expect that many ORMs would be able to help with this as well. 

The stuff you need to do to manage this specific use case won't be too hard, but then you go and start working on the next use case, and the next, and so on.  Pretty soon, you'll have written a fair subset of a business objects framework.
D. Lambert Send private email
Thursday, April 24, 2008
You need to go read this book now:

Domain Driven Design: Tackling COmplexity in the Heart of Software, by Eric Evans.
Chris Tavares Send private email
Saturday, April 26, 2008
Thanks for the answers

I was (somewhat) familliar with CSLA, but I haven't actually used it anywhere.  I took a brief look at the documentation before I posted here, but for the life of me I can't find any mention on where the business rules for deleting objects are located.
Radu094 Send private email
Saturday, April 26, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz