when to use CSLA BO's, why, and some how

when to use CSLA BO's, why, and some how

Old forum URL: forums.lhotka.net/forums/t/2574.aspx


EricF posted on Wednesday, March 21, 2007

I use programming only occassionally to supplement my professional work as a manager in an architectural design firm, so please forgive or ignore parts of my questions that may have more to do with weak skills vs CSLA specifically. I feel more comfortable with aspects of CSLA features (authorization, validation, etc.) than overall usage right now.

Consider a set of classes designed to implement Money as a core business library object, with the focus on Currency to keep this more focused. My first non CSLA attempt at this resulted in a public class named Currency, which contains a nested public struct of currency aspects of interest called CurrencyInfo and a generic SortedList with the ISO currency code as the key and the associated CurrencyInfo struct as the value. The class is instantiated with a constructor that takes either a currency code or CultureInfo code, and the static list is built if necessary. There are convenience constructors for common currencies (ie, USD).

Applying CSLA to this leaves me scratching my head in a few places.

The CurrencyInfo struct can be a read only BO, but what do I gain from this. Data binding?

The Currency class itself should(?) then be implemented as a NameValueListBase I guess. but
(1) what do I gain from this considering the information is not kept statically but generated from the Net framework itself (why there isn't such a class in Net as there is in java is a different question), has no authorization or validation concerns?
(2) how do I sort this after its built?
(3) anything in CSLA that aids a singleton class, or is that just irrelevant?

Questions, comments, answers most welcome (Eric is NOT my real name if the answer is read the damn book again, dude Smile [:)])




Bayu replied on Thursday, March 22, 2007

Hey,

Based on just your currency sample I would say that Csla might be a bit overkill for your purposes.

What Csla provides is primarily this:
- objects that support full databinding
- validation, authentication and authorization
- persistency model (DataPortal) that allows transparent scaling from a single-machine solution to a distributed solution using just a config setting

To answer your questions:

1) For your currencies you wouldn't gain much (see my list above) since it is readonly and only uses the databinding feature. You wouldn't really need Csla just to make a readonly lookup list lke this bindable (simple objects with (readonly) properties that you put in a List will do a fine job too

2) Sorting is primarily a UI issue while your CurrencyList is primarily a Business Object (BO). What I mean here is that it 'should' not be the responsibility of CurrencyList BO to enable sorting. In order to solve the sorting requirement in your UI you should have a look at the SortedBindingList. Schematically the solution is to bind your BO to the SortedBindingList which in turn you bind to your Control (Grid/ComboBox/...). All sorting requirements that you have can be addressed by the SortedBindingList that sits between your BO and UI:

BO --> SortedBindingList --> UI

3) You can certainly cache lists in memory. Since all Csla objects are instantiated through factory methods it is really easy to maintain a static (shared) copy of a list inside your BO which is returned in every request after the first. But note that for most applications that Csla targets the assumption is that multiple users interact with your data and therefore that any cached data can become stale easily, speaking for myself: I hardly use caching especially since most of these lists are really small and can be fetched from the DB cheaply.

For your currency list however cahcing would be a logical thing to do, since I guess it does not get outdated so fast.

Hope this helps.

Bayu

Copyright (c) Marimer LLC