D
David C
In my business layer, I have Person, and Patient which derives from
Person.
//base class for all single classes
public class BaseItem{}
public class Person:BaseItem{}
public class Patientersons{}
Then I have a collection class for each of the above. Notice that the
pattern of inheritance follows that of the single classes. Just as
Person inherits from BaseItem, Persons inherits from BaseItems, and
just as Patient inherits from Person, Patients inherits from Persons.
public class BaseItems:ArrayList{}
public class Persons:BaseItems{}
public class Patients : Persons{}
This design pattern worked pretty well with 1.1. The collection class
Patients only had instances of Patient, but obviously only the naming
convention kept me from adding to Patients instances of other
classes. There is no type safety.
So enter List<T>. With this, I would like Persons to have instances
of only Person, and Patients only instances of Patient. This is what
I have so far.
public class BaseItems<T>:List<T> where T:BaseItem
{}
public class Persons:BaseItems<Person>
{}
So far so good. I am stomped at Patients. I want it to inherit from
Persons (I don't want to get into why.), but in Patients, I would like
to allow only instances of Patient. Thanks in advance.
(Addendum) If you must know the justification behind my inheritance
pattern of collection classes, please read on. Someone from another
forum asked why not just just use plain List<Person> and
List<Patient> ?
Here is my current design pattern. While not type safe, it has worked
pretty well.
BaseItems:ArrayList - This is the base class to all Collection
classes. It has all the data classes necessary to retrieve rows of
data necessary to populate collections.
Persons:BaseItems - This is a base class to Patients, Doctors, and
Nurses (I am making this up at this point, but the pattern is similar
my project). That is because the same table stores patients, doctors
and nurses. The Persons class knows all that.
Patientsersons
Doctorsersons
Nursesersons
This is what my client code looks like
Patients patients = new Patients();
//get all patients and only patients in California
patients.FilterState = 'CA';
patients.Retrieve();
//get all persons (patients, doctors, nurses) in California
Persons persons = new Persons();
persons.FilterState = 'CA';
persons.Retrieve();
Person.
//base class for all single classes
public class BaseItem{}
public class Person:BaseItem{}
public class Patientersons{}
Then I have a collection class for each of the above. Notice that the
pattern of inheritance follows that of the single classes. Just as
Person inherits from BaseItem, Persons inherits from BaseItems, and
just as Patient inherits from Person, Patients inherits from Persons.
public class BaseItems:ArrayList{}
public class Persons:BaseItems{}
public class Patients : Persons{}
This design pattern worked pretty well with 1.1. The collection class
Patients only had instances of Patient, but obviously only the naming
convention kept me from adding to Patients instances of other
classes. There is no type safety.
So enter List<T>. With this, I would like Persons to have instances
of only Person, and Patients only instances of Patient. This is what
I have so far.
public class BaseItems<T>:List<T> where T:BaseItem
{}
public class Persons:BaseItems<Person>
{}
So far so good. I am stomped at Patients. I want it to inherit from
Persons (I don't want to get into why.), but in Patients, I would like
to allow only instances of Patient. Thanks in advance.
(Addendum) If you must know the justification behind my inheritance
pattern of collection classes, please read on. Someone from another
forum asked why not just just use plain List<Person> and
List<Patient> ?
Here is my current design pattern. While not type safe, it has worked
pretty well.
BaseItems:ArrayList - This is the base class to all Collection
classes. It has all the data classes necessary to retrieve rows of
data necessary to populate collections.
Persons:BaseItems - This is a base class to Patients, Doctors, and
Nurses (I am making this up at this point, but the pattern is similar
my project). That is because the same table stores patients, doctors
and nurses. The Persons class knows all that.
Patientsersons
Doctorsersons
Nursesersons
This is what my client code looks like
Patients patients = new Patients();
//get all patients and only patients in California
patients.FilterState = 'CA';
patients.Retrieve();
//get all persons (patients, doctors, nurses) in California
Persons persons = new Persons();
persons.FilterState = 'CA';
persons.Retrieve();