CSLA 2.1.4: ReadOnlyBase

CSLA 2.1.4: ReadOnlyBase

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


cjherasmus posted on Thursday, May 03, 2007

Good Day,

I've created a readonlybase BO which has amonst others, a latitude and a longitude property. I would like the developer to be able to choose between display formats, i.e. degrees, minutes, seconds or decimal degrees. The database stores degrees ,minutes and seconds in separate fields. I have a conversion routine to convert back and forth between the two options.

My question:

Should I build the conversion routine into my derived readonlybase BO or should I enhance the original base class with an additional overriden "ToDMS" or "ToDecimalDegrees" method similar as "ToString". I might want to use this routine in more than one derived BO?

My next question:

I also have a routine that convert strings to proper case. The database stores all capital letters so I would like to populate my BO with the proper case strings. As with previous question, where should I implement my conversin routine?

Hope, it's all clear.

Thanks

RockfordLhotka replied on Thursday, May 03, 2007

If you have methods (behaviors) that may be used by many objects, then you should normalize those behaviors into their own objects.

It sounds to me like you should probably have a GeographicCoordinate class that contains functionality around latitude and logitude values.

Similarly, you might have a StringUtilities class to contain helper methods related to string values.

But here's the fun part: you may very likely decide to have a ToDecimalDegrees method on your ROB business class, because that may be the most logical and discoverable place for such a method. The important thing to understand is that the behavior implementation is never duplicated, but rather you are merely using that behavior from multiple locations.

You can think of it much like the My namespace in VB. Most of the functionaltiy exposed by My is buried somewhere in the .NET base class library. Technically you could go find it all and cobble together your own abstractions. But My provides some common abstractions and shortcuts for you, so you don't have to write them yourself. They do not duplicate logic, but rather they just expose or abstract it in useful ways.

That's a good model. Write a behavior one time, then use it where needed, providing abstractions or discoverable entry points where appropriate.

cjherasmus replied on Wednesday, May 09, 2007

Thanks, Rocky.

Just to make sure I understand correctly

If I use a "ToDecimalDegrees" method within the ROB business class, I could do something like:

textBox1.Text = Point.Latitude.ToDecimalDegrees();

where "Point" is the ROB and "Latitude" is a property.

But wouldn't this mean that I will have to create a special data type ?

Or do you mean something like:

textBox1.Text = Point.ToDecimalDegrees(StringFormat);

Regards,

Copyright (c) Marimer LLC