OOP - Contact Management System - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

OOP - Contact Management System

I'm fairly new to Object Oriented Programming, so here's what I'm wondering.

I'm working on a Contact Management system, where a contact can either be Person or a Business. My thinking is to have a base class called Contact and two classes derived from it, Person and Business.

In my database, I'd like to store all the information in one table and distinguish the contacts by a foreign key field, ContactTypeID for example.

At times in my code, I need to fill a collection of Contacts, including a mix of People and Businesses. For example, I may be looping through a result set and creating the objects as I loop. In such an example, what's the best way to determine which object I should be creating?

Adding a SELECT CASE item(i).ContactTypeID seems to defeat the purpose of OOP because if I ever decide to add a third contact type (or fourth), updating the code would become a nightmare.

I'm wondering if anyone has encountered a similar scenario and could shed some light on the matter.

Thanks in advance,
Chris

Comments

  • shrekshrek Posts: 18Member
    if you've got problem like this it's mean that your classes don't model reality (in this case database 'reality' so good). in typical case we create one object for one database table. if you really need two different classes you have to use (bleeeee :) ) swich or if statement because there isn't simple oo way to translate relational model database to oo model programming.


Sign In or Register to comment.