none
Deriving from a base class RRS feed

  • Question

  • Hi,

     

    I usually derive all my classes from a base class.  That is all Data Access classes derive from a base Data Access class. All Business Process classes derive from a base Business Process class. All Web   In some cases the base class does not contain any functionality at all, I just derive it in case I need to add common functionality at a later stage.  This also includes Web Forms as well.  Is this a good practice in general?

     

    Thanks

    Arjuna.

    Friday, June 8, 2007 9:00 AM

All replies

  • I myself often use empty base classes or interfaces just to be able to write my code for more general situations, for example, if you inherit all business entities from an Entity class, you are able to do things like List<Entity>, even if your Entity class contains no data or methods.

    This is neither a good or bad practice in itself. It is just a common design pattern that has its advantages (like being able to easily inherit behavior) and disadvantages (like losing the opportunity to use inheritance for other purposes).

    I recommend reading Martin Fowler's "Enterprise Application Patterns", which is a collection of several design patterns (including the one you are describing) so you can learn the different ways to structure your application for different situations.

    http://www.martinfowler.com/books.html

    I am not related to the author or the publisher, look around on the net and you will find that this book is the most complete study of this subject.


    Friday, June 8, 2007 9:20 AM