Re: OO question

Re: OO question

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


ozitraveller posted on Sunday, May 27, 2007

Hi

In the Csla view of the world what is the recommended way to incorporate a set of common functions in an application? For example I have a couple of functions that are used in more that one business object, do I include the function in all BO's to maintain encapsulation or do I group then together in a static class and just call them? I don't like the idea of having duplicate copies as general rule.

Any input would be greatly appreciated.

Thanks

RockfordLhotka replied on Tuesday, May 29, 2007

From a design perspective, you should normalize behaviors that are duplicated across objects into a central object. The original objects can then collaborate with this new object to gain access to those behaviors.

In other words, you are absolutely correct. Do not duplicate behaviors. Centralize them into new object(s). Then call these new objects from the original locations where the behaviors would have been. In many cases these new objects are non-public (frequently Friend/internal).

From an implementation perspective, these new "objects" are often Module or static class constructs, with Shared/static methods that implement the behaviors. However, a given class/Module should only contain related behaviors. In other words, preserve cohesion by keeping related methods together, and putting non-related methods into different classes.

This is the difference between design and implementation. At the design level everything is an object, so these static classes are "objects" with behaviors. At an implementation level we often choose to implement the "objects" as classes with Shared/static methods for efficiency reasons. Even so, logically these things are still objects and should be designed following OOD - with encpasulation, cohesion, etc.

ozitraveller replied on Tuesday, May 29, 2007

Thanks Rocky.

That's sort of where I was going.

Copyright (c) Marimer LLC