Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 57265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:39:51+00:00 2026-05-10T17:39:51+00:00

I want to ask a question about how you would approach a simple object-oriented

  • 0

I want to ask a question about how you would approach a simple object-oriented design problem. I have a few ideas of my own about what the best way of tackling this scenario, but I would be interested in hearing some opinions from the Stack Overflow community. Links to relevant online articles are also appreciated. I’m using C#, but the question is not language specific.

Suppose I am writing a video store application whose database has a Person table, with PersonId, Name, DateOfBirth and Address fields. It also has a Staff table, which has a link to a PersonId, and a Customer table which also links to PersonId.

A simple object oriented approach would be to say that a Customer ‘is a’ Person and therefore create classes a bit like this:

class Person {     public int PersonId { get; set; }     public string Name { get; set; }     public DateTime DateOfBirth { get; set; }     public string Address { get; set; } }  class Customer : Person {     public int CustomerId { get; set; }     public DateTime JoinedDate { get; set; } }  class Staff : Person {     public int StaffId { get; set; }     public string JobTitle { get; set; } } 

Now we can write a function say to send emails to all customers:

static void SendEmailToCustomers(IEnumerable<Person> everyone) {      foreach(Person p in everyone)         if(p is Customer)             SendEmail(p); } 

This system works fine until we have someone who is both a customer and a member of staff. Assuming that we don’t really want our everyone list to have the same person in twice, once as a Customer and once as a Staff, do we make an arbitrary choice between:

class StaffCustomer : Customer { ... 

and

class StaffCustomer : Staff { ... 

Obviously only the first of these two would not break the SendEmailToCustomers function.

So what would you do?

  • Make the Person class have optional references to a StaffDetails and CustomerDetails class?
  • Create a new class that contained a Person, plus optional StaffDetails and CustomerDetails?
  • Make everything an interface (e.g. IPerson, IStaff, ICustomer) and create three classes that implemented the appropriate interfaces?
  • Take another completely different approach?
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:39:51+00:00Added an answer on May 10, 2026 at 5:39 pm

    Mark, This is an interesting question. You will find as many opinions on this. I don’t believe there is a ‘right’ answer. This is a great example of where a rigid heirarchial object design can really cause problems after a system is built.

    For example, lets say you went with the ‘Customer’ and ‘Staff’ classes. You deploy your system and everything is happy. A few weeks later, someone points out that they are both ‘on staff’ and a ‘customer’ and they are not getting customer emails. In this case, you have a lot of code changes to make (re-design, not re-factor).

    I believe it would be overly complex and difficult to maintain if you attempt to have a set of derived classes that implement all the permutations and combination of people and their roles. This is especially true given that the above example is very simple – in most real applications, things will be more complex.

    For your example here, I would go with ‘Take another completely different approach’. I would implement the Person class and include in it a collection of ‘roles’. Each person could have one or more roles such as ‘Customer’, ‘Staff’, and ‘Vendor’.

    This will make it easier to add roles as new requirements are discovered. For example, you may simply have a base ‘Role’ class, and derive new roles from them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want ask some question about asp.net mvc Is static constructor will init every
The question I want to ask is thus: Is casting down the inheritance tree
I want to ask how other programmers are producing Dynamic SQL strings for execution
I want to ask in which phase of Control Execution Lifecycle is the Server-Side-Code
I want to ask you if there is a possibility to program a Java
At the risk of being downmodded, I want to ask what the best mechanism
as google does not deliver what i want to know, i try to ask
Want to know what the stackoverflow community feels about the various free and non-free
I'm kind of curious how I should approach a problem with iPhones and communication
I'm a bit scared to ask this question as it may start a religous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.