Take the 2-minute tour ×

I recently converted an old application that was using XML files as the data store to use SQL instead. To avoid a lot of changes I basically created ActiveRecord style classes that inherited from the original business objects.

For example

SomeClassRecord :SomeClass
//ID Property
//Save method

I then used this new class in place of the other one, because of polymorphism I didn't need to change any methods that took SomeClass as a parameter.

Would this be considered 'Bad'? What would be a better alternative?

share|improve this question
What do you mean by "bad?" Does it meet your customer's requirements for functionality and maintainability? –  Robert Harvey Aug 2 '12 at 22:59
add comment

2 Answers

up vote 1 down vote accepted

I would not say this is a 'Bad' thing to do. But there are alternatives with their own trade-offs.

Assuming that the way the original classes were used was the ActiveRecord pattern, here are some alternatives.

  1. Modify each business object's Save() method to delegate the saving work to a class responsible for dealing with storage, whether it's XML or SQL. Instead of decorating each class, you delegate the saving to a single interface, say, IDataStore. For example:

    public class SomeClass {
        IDataStore dataStore; // how this gets set can vary also
        public void Save() {

    Now the change is in the implementation of IDataStore.

  2. Continue using your business objects in the business layer, but when doing data access, map your business objects to data access objects, and use the Repository pattern. For example:

    public class SomeBusinessProcess {
      public void DoSomeWork(SomeClass someClass) {
        // ... do some work on someClass ...
        // now save
        SomeClassDAO someClassDao = AutoMapper.Map<SomeClass, SomeClassDAO>(); // can use AutoMapper, for example

You really can take it as far as you want, based on what your needs are.

share|improve this answer
add comment

In no way is this is not a 'bad' thing to do. What you did is akin to the decorator pattern. http://www.dofactory.com/Patterns/PatternDecorator.aspx

In fact I suggest that you do read up on the decorator pattern as its a useful tool to have in your design arsenal.

share|improve this answer
add comment

Your Answer


