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 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
  • 0 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-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

Ask A Question

Stats

  • Questions 253k
  • Answers 253k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Do you mean something like this? $this->data['Flo']['name'] = $value; $this->Flo->save($this->data); May 13, 2026 at 9:59 am
  • Editorial Team
    Editorial Team added an answer Now it works fine, I need to stat localserver first… May 13, 2026 at 9:59 am
  • Editorial Team
    Editorial Team added an answer The line test2 = new Vector(new double[] { 3, 3,… May 13, 2026 at 9:59 am

Related Questions

I am trying to design an object model (for C#), and can't work out
I'm building a food logging database in Django and I've got a query related
I'm not well versed in domain driven design and I've recently started created a
I am trying to write an Audit Log method that will log all changes
I am knocking together a WPF demo for our department at work to show

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.