Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
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,
0 · ·