Keeping different versions of a class synchronized

Keeping different versions of a class synchronized

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


bgilbert posted on Monday, April 13, 2009

This is probably more of an OO question than a CSLA question.

For several of my business object classes, I need to maintain both BusinessBase and ReadOnlyBase versions. I'm trying to figure out the best way to prevent having to maintain duplicate code in both classes. An interface only gets me part of the way there. Any suggestions?

RockfordLhotka replied on Monday, April 13, 2009

Even though an editable object and read-only object might have similar properties, it is unlikely that any of their code is in common.

Even the property code is different, because the editable object will have read-write properties and the read-only object will have read-only properties.

The editable object will have business and validation rules, the read-only object won't.

They both might have some authz rules, but the editable object will allow/deny write, and the read-only object won't.

So in the end, the only code that might be close enough to reuse would be your data portal fetch method. There are several ways to build a data access layer that would allow reuse of the data retrieval code to load two different objects with the same (or very similar) properties.

If your DAL returns a DataReader, and the objects have very similar properties, you could get away with loading both objects from a common DataReader (reuse the same DAL method).

If your DAL returns a DTO, and the objects have very similar properties, you could get away with loading both objects from a common DTO (reuse the same DAL method).

And I'm sure there are other variations on that theme - you could use reflection, etc.

Copyright (c) Marimer LLC