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

  • SEARCH
  • Home
  • 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 94833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:33:48+00:00 2026-05-10T23:33:48+00:00

I am trying to design an object model (for C#), and can’t work out

  • 0

I am trying to design an object model (for C#), and can’t work out the best way to store the data. I’ll try to use a simple example to illustrate this!

I have an object ‘pet’, which could be one of, ‘cat’, ‘dog’ etc. So I have created an ‘pet’ class with a ‘petType’ enum to store this.

Now this is where it gets tricky. If an ‘pet’ is a ‘cat’, then its ‘food’ could be one of ‘fish’, ‘milk’ etc. If it is a ‘dog’ then its ‘food’ could be ‘meat’, ‘biscuits’ or something.

Now should I create a big enum for ‘fish’, ‘milk’, ‘meat’ and ‘biscuits’ and somehow code it so that a ‘cat’ cannot be assigned ‘food.meat’? It wouldnt really make sense for my ‘pet’ class to have a ‘catfood’ and ‘dogfood’ enum, because thats not extensible and it will end up storing loads of enums that are null.

Is there an elegant solution to this that I’m not seeing?

  • 1 1 Answer
  • 1 View
  • 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-10T23:33:49+00:00Added an answer on May 10, 2026 at 11:33 pm

    Try #2. Seems to be correct

    interface IPet { }  class Cat : IPet {     public void eat(CommonFood food) { }     public void eat(CatFood food) { } }  class Dog : IPet {     public void eat(CommonFood food) { }     public void eat(DogFood food) { } }  interface IFood { }  abstract class CommonFood : IFood { }  abstract class CatFood : IFood { }  abstract class DogFood : IFood { }  class Milk : CommonFood { }  class Fish : CatFood { }  class Meat : DogFood { }  class Program {     static void Main(string[] args)     {         Dog myDog = new Dog();         myDog.eat(new Milk()); // ok, milk is common         myDog.eat(new Fish()); // error     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out the best way to design Car and Road objects
I'm trying to design an application that can identify COM objects and their properties
I'm trying to design an entity model for an application that uses ASP.Net membership
I am trying to design my first Android application with the use of GPS.
I'm trying to figure out how to design a small application more elegantly, and
I am trying to adhere to best multi-layer design practices, and don't want my
I am trying to come out with a good design for the storage of
I'm trying to do things the DDD (domain driven design) way. And boy do
I'm trying to use domain driven design while creating a website that is publicly
I am trying to design a model in which I have a List of

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.