Object Inheritance Help

Object Inheritance Help

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

GPhillips posted on Wednesday, July 28, 2010

I started with an inheritance module used with CSLA 2.0 and I am trying to rewrite it to use 3.8.1 and
lambda expressions with the PropertyInfo/Field manager model.  The original inheritance looked like this:

      BankAccountBase (or other business classes-autogenerated based on a SQL DB)
         BankAccount  (for custom Properties/Methods not autogenerated)

Rewritten version:

BusinessBase(Of T)
   Entity(Of T As Entity(Of T))  Inherits BusinesBase(Of T)
      BankAccountBase(Of T As BankAccountBase(Of T))   Inherits Entity(Of T)
         BankAccount(Of T As BankAccount(Of T))   Inherits BankAccountBase(Of T)

This works properly with PropertyInfo, FieldManager and lambda expressions.  Just using Entity without
without the (Of T) causes downstream classes to blow up with a PropertyInfo locked error. 

My problem is that I have many routines that operate on the Entity class (including Custom Controls
that have an Entity property).  This worked fine with the original hierarchy since everything was
derived from Entity, but with the new method, these would have to be Entity(Of T) and the type would
have to be specified all the time, which isn't feasible.

One attempt I have made is to create an IEntity Interface that Entity(Of T) would implement.  The
concern I have about that route is that EVERY property, event and Sub that is needed from both
Entity(Of T) AND BusinessBase(Of T) (like IsNew, Is Valid, Save, etc, etc.) need to be part of the
interface and have to be Shadowed and raised (or returned) in Entity(OF T).  This seems overly

Has anyone else run into a similar situation? Is an interface the right approach or is there another
way to access the base classes?.

Any help/ideas would be GREATLY appreciated.



JonnyBee replied on Monday, August 02, 2010

Hi Gary,

Your only option with generic classes is to use Interfaces. But - not every property has to be in that interface as there are other standard interfaces you could use in Csla as ITrackStatus, ISavable etc. And  you can have inheritance in interfaces as:

Public Interface IA
    Sub A()
End Interface

Public Interface IB
    Sub B()
End Interface

Public Interface IC
    Inherits IA, IB
    Sub C()
End Interface

Copyright (c) Marimer LLC