Noobie question on inheritance

Noobie question on inheritance

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


mdonato posted on Wednesday, March 28, 2007

Hello all:

I am almost finished (I guess 100 pages left on a 600 page book is almost) with Expert VB 2005 Business Objects. While I understand the individual concepts and procedures, grasping the entire framework as a whole has proved to be a challenge.   The framework has come a long way since the VB6 book.

I work for a school and  I am creating a BO layer to work with an existing records database.  I have a person object that keeps all the properties that are common to all individuals in the database (eg FirstName, LastName, etc). This object inherits from ReadOnlyBase because my application cannot change the data in the database.

I would like to create a student object that inherits all the properties of the person object.  My initial attempt was this:

<Serializable()> Public Class Student
      Inherits Person

However, that does not work because Person does not have a public constructor and I know that creating one would break the shared factory method of creating objects.  I'm sure I'm just missing something. Any help would be greatly appreciated.

Thanks,

Marcello Doanto

Christian Brothers HS

 

ajj3085 replied on Wednesday, March 28, 2007

Hi,

The most common advise here is that you should not use inheritence to get properties, you should do so to again the behaviors of the superclass.

Going with that, I would suggest that Person is just a DTO (Data transfer object) that exists in your BO library to support the business objects, but it should not be publicly accessible from your UI layer; instead, it would be an internal class.

Your Student class would use Person in its DataPortal_Fetch method to load the relevent person data.  You could have a static factory method on Person that actually performs the load.

Of course you may opt to create a GetStudent stored procedure that returns the person data as well as student specific data. How your DataPortal_Fetch works is up to you based on your database design.

HTH
Andy

hurcane replied on Wednesday, March 28, 2007

Person needs to have a Protected constructor to use inheritance.

Copyright (c) Marimer LLC