473,666 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Populate Base + Child Class Fields

Suppose I have a system that keeps track of 5 different types of "People".

My intent is to have a base Person class, then 5 derived classes for each of
the specific person types (e.g., Patient, Doctor, Employee, Contractor,
etc).

Now, at runtime I need to retrieve all the property values from a database
and populate all of the fields of both the base and derived classes. Not all
fields will need to be exposed via public properties as they will be used
internally (to the class).

I would like to have one single method that talks to the DAL and populates
all fields.

What is the standard (or at least an acceptable) way to make this happen?
Should I put some "PopulateMe ()" method (which calls the DAL) in the derived
class AND have it populate the base class fields? Something just doesn't
seem right about doing it that way... but the alternative would apparently
be to have some sort of "PopulateMe ()" method in both the base class and
derived class - each one populating its respective fields. But that seems
sort of wrong as well.

Thoughts? Opinions? Perspective? Recommendations ?

Thanks!
Mar 2 '06 #1
3 5321
What I would do in the abstract base class is create a private Method
"PopulateBase() " that populates the base properties. Then I would create an
abstract method called "PopulateMe ()". Each derived class's "PopulateMe ()"
method would call base.PopulateBa se(), and then populate it's specific
properties.

public abstract People
{
private void PopulateBase()
{
//Populate the base properties.
}
abstract public PopulateMe();
}

public Doctor : People
{
override public PopulateMe()
{
base.PopulateBa se();
//Start populating the Doctor Properties.
}
}

Just an idea.....

"Jordan" wrote:
Suppose I have a system that keeps track of 5 different types of "People".

My intent is to have a base Person class, then 5 derived classes for each of
the specific person types (e.g., Patient, Doctor, Employee, Contractor,
etc).

Now, at runtime I need to retrieve all the property values from a database
and populate all of the fields of both the base and derived classes. Not all
fields will need to be exposed via public properties as they will be used
internally (to the class).

I would like to have one single method that talks to the DAL and populates
all fields.

What is the standard (or at least an acceptable) way to make this happen?
Should I put some "PopulateMe ()" method (which calls the DAL) in the derived
class AND have it populate the base class fields? Something just doesn't
seem right about doing it that way... but the alternative would apparently
be to have some sort of "PopulateMe ()" method in both the base class and
derived class - each one populating its respective fields. But that seems
sort of wrong as well.

Thoughts? Opinions? Perspective? Recommendations ?

Thanks!

Mar 2 '06 #2
I'd like to correct myself. Declare PopulateBase() as protected.

public abstract class People
{
protected int m_baseValue;

protected void PopulateBase()
{
this.m_baseValu e = 10;
}

abstract public void PopulateMe();

}

public class Doctor : People
{
private int m_doctorValue;

public override void PopulateMe()
{
base.PopulateBa se();
this.m_doctorVa lue = 20;

}
}

"rmacias" wrote:
What I would do in the abstract base class is create a private Method
"PopulateBase() " that populates the base properties. Then I would create an
abstract method called "PopulateMe ()". Each derived class's "PopulateMe ()"
method would call base.PopulateBa se(), and then populate it's specific
properties.

public abstract People
{
private void PopulateBase()
{
//Populate the base properties.
}
abstract public PopulateMe();
}

public Doctor : People
{
override public PopulateMe()
{
base.PopulateBa se();
//Start populating the Doctor Properties.
}
}

Just an idea.....

"Jordan" wrote:
Suppose I have a system that keeps track of 5 different types of "People".

My intent is to have a base Person class, then 5 derived classes for each of
the specific person types (e.g., Patient, Doctor, Employee, Contractor,
etc).

Now, at runtime I need to retrieve all the property values from a database
and populate all of the fields of both the base and derived classes. Not all
fields will need to be exposed via public properties as they will be used
internally (to the class).

I would like to have one single method that talks to the DAL and populates
all fields.

What is the standard (or at least an acceptable) way to make this happen?
Should I put some "PopulateMe ()" method (which calls the DAL) in the derived
class AND have it populate the base class fields? Something just doesn't
seem right about doing it that way... but the alternative would apparently
be to have some sort of "PopulateMe ()" method in both the base class and
derived class - each one populating its respective fields. But that seems
sort of wrong as well.

Thoughts? Opinions? Perspective? Recommendations ?

Thanks!

Mar 2 '06 #3
"Jordan" <A@B.COM> a écrit dans le message de news:
%2************* ***@TK2MSFTNGP1 0.phx.gbl...

| Suppose I have a system that keeps track of 5 different types of "People".
|
| My intent is to have a base Person class, then 5 derived classes for each
of
| the specific person types (e.g., Patient, Doctor, Employee, Contractor,
| etc).

As well as what rmacias says, you might like to consider using the Visitor
pattern to do the populating, then you don't have to include the populating
code in the business classes; what is more, you could change what the
visitor does if you decide to change storage medium.

You might also like to consider what would happen if a Person could be both
a Doctor and a Patient, depending on how sick they were :-)

In this situation, you should not use inheritance but composition to express
the concept of a Role.

You need a base class Role from which you derive Patient, Doctor, Employee,
Contractor, etc; then you add a list of 0..n Roles in the Person class.

This then allows a Person to have no Roles, through to multiple simultaneous
Roles.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Mar 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2660
by: thechaosengine | last post by:
Hi all, I wanted to put some common security functions into a class that inherits from the Page class and then use the new class as the basis for all my pages. Unfortunately, if I try and inherit from my new SecurePage class and not the old Page class, the designer breaks and will only allow me into html mode. Bugger. The error message given is:
20
2879
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
9
5117
by: Martin Herbert Dietze | last post by:
Hello, I would like to implement a callback mechanism in which a child class registers some methods with particular signatures which would then be called in a parent class method. In half-code this should in the end look like this: In the child class:
3
1367
by: Tomislav Bartolin | last post by:
Hi I'm trying do create a generic base class for all of my data objects. One of the main requirements for this class is to be able to handle all common db actions without need for implementing them in inherited classes. To accomplish this I need a way to map values of class fields to corresponding stored procedure parameters. The only way i have figured out to do this would be to create a name-value struct array and hold class fields...
5
5826
by: owais | last post by:
Hi, I have a problem, I want to implements Parent class interface methods in child class. for e.g -------------- Test1.vb ---------------- Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Globalization
7
2535
by: Paul | last post by:
Hello, I'm coming from a PHP background and am working on a large-scale VB.NET project. One of the cornerstones of this project is a reusable form class, to standardize our web forms. My goal is to have a true hierarchical parent form class with child form element classes. The programmatic code would be something like this, ideally (sorry about the lame names, but it's just for demo):
4
1790
by: mwebel | last post by:
Hi, i have another problem: i have a container basis class and want to write a virtual "copyFrom()" function. Basically the child class should copy from another child class. ************************ class Basis{ public: virtual void copyfrom(basis & obj)=0;
12
2335
by: y-man | last post by:
Hi, I am creating a child class of the vector, which contains a couple of functions to make the work with carthesian coordinate vectors easier. To make things work more easily, I would like to be able to access the vector through a string which is either x, y or z. So that I can use: ---xyzvec.hh-- #ifndef XYZVEC_HH #define XYZVEC_HH
7
1319
by: Daniel Smedegaard Buus | last post by:
Hello there :) I'm trying to implement some basic DRY MVC-like functionality as a basis to work on. Specifically, I'd like to create a base abstract model class with basic read, write, delete and update database functionality, that I can use for all models in my code. I'd pretty much like it to go like this (if there are a few errors, you'll have to forgive me, I just woke up and I don't have the code on me, getting ready to go to work,...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.