Interfaces: Improving the Iterating Business Object
Is the IBO REALLY a Good Idea?
The first question is whether I should really have an iterating business object at all or whether I should merely decorate a business object with an iterator. On the one hand it does seem unnecessary for a single record to have first(), next() and isLast() methods (if, for instance, you UserService.getByUniqueAttribute(“UserID”,“17”)). On the other hand, I like to be able to reuse object views and I have views that could conceivably be used by a single object or by a collection of objects (not many, but they exist).
The fact that when I return a single record I also happen to have iteration methods (which do no harm) is to me a small price to pay for the simplicity of a single object for returning all recordsets – whether they return 1 or n records. And the fact that I only have one set of syntax to remember and use for all my views (whether designed to display 1 record, n records or both) is just an added benefit.
Model vs. View The real problem with my IBO right now is that in my rush to get a project out I dropped in some base methods that I know should be part of my view. Specifically I added a DisplayValue(), DisplayField and an InputtoValue() method. The first two (displaying the value as nicely formatted HTML and displaying the HTML field(s) to use for editing the attribute) should really be handled by an IBO HTML decorator. The InputtoValue() implements custom data object specific transformations. For example, imagine a USPhoneNumber data type which displays three fields for the three parts of the phone number. The inputtoValue() method for attributes with a USPhoneNumber custom data type would appropriately concatenate the three fields to return a single value. It is a cool feature, but it should be called by the controller – not part of the model.
The IBO Interface So, what does that leave us with as the interface for our IBO? first(), isLast(), next(), get(), isGettable(), set(), isSettable() are the core methods. But then we need to handle loading and some other advanced methods for ordering, filtering and paging. But lets break those into two separate posts.



There are no comments for this entry.
[Add Comment]