Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Basic Design Question

Basic Design Question

Scheduled Pinned Locked Moved C#
questionhelpdesigntutoriallearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skoder
    wrote on last edited by
    #1

    Hello, i have a (probably) very basic design question. I need to create a Person Object which holds information like Name, Email, Age, and Gender. The problem is the Gender information. There can only be "Man" and "Woman". Soo i could either create a Man and Woman object which inherits from the Person object, or i could maybe store the information as an int, boolean or maybe even better as an Enumeration ? But i cant decide which is the "correct" way to do it. The Man and Woman object will be completly identical except for their type (how they are declared - new Man() and new Woman() ..). Or should I in this case go with the other option and store the information as an int/boolean/Enum in the Person object ? And is that how it is done when you have a value than can only be a certain different set of values ? Or something completly else ? There is no really difference as far as i can see, as i will either have to do checks like - if (myObj.Gender == "Man"), or if (myObj is "Man") of course i could do some overloading of the methods soo i dont even have the if else - like HandleThis(Man obj) and HandleThis(Woman obj). Maybe for the scalability, escpecially if it had been other information i had to store which could change by time it would probably be best to go with the inhertiance example. or maybe i should always go with that solution ? To some of you this might be a stupid question, but i cant really decide. Soo i hope someone can help me to tell me what is the "correct" way to do it and why. Martin Happy New Year everyone ! :)

    X E 2 Replies Last reply
    0
    • S Skoder

      Hello, i have a (probably) very basic design question. I need to create a Person Object which holds information like Name, Email, Age, and Gender. The problem is the Gender information. There can only be "Man" and "Woman". Soo i could either create a Man and Woman object which inherits from the Person object, or i could maybe store the information as an int, boolean or maybe even better as an Enumeration ? But i cant decide which is the "correct" way to do it. The Man and Woman object will be completly identical except for their type (how they are declared - new Man() and new Woman() ..). Or should I in this case go with the other option and store the information as an int/boolean/Enum in the Person object ? And is that how it is done when you have a value than can only be a certain different set of values ? Or something completly else ? There is no really difference as far as i can see, as i will either have to do checks like - if (myObj.Gender == "Man"), or if (myObj is "Man") of course i could do some overloading of the methods soo i dont even have the if else - like HandleThis(Man obj) and HandleThis(Woman obj). Maybe for the scalability, escpecially if it had been other information i had to store which could change by time it would probably be best to go with the inhertiance example. or maybe i should always go with that solution ? To some of you this might be a stupid question, but i cant really decide. Soo i hope someone can help me to tell me what is the "correct" way to do it and why. Martin Happy New Year everyone ! :)

      X Offline
      X Offline
      Xodiak
      wrote on last edited by
      #2

      just use and enumeration, inheritance from a person object would be too much normalization...its very unlikely humanity will converge into anything other than a man or woman, so a simple enumeration would be perfect. You might consider not having a default constructor and instead have a consturcture that requires a gender initialization.
      normailization is good, but there is always to much of a good thing...

      1 Reply Last reply
      0
      • S Skoder

        Hello, i have a (probably) very basic design question. I need to create a Person Object which holds information like Name, Email, Age, and Gender. The problem is the Gender information. There can only be "Man" and "Woman". Soo i could either create a Man and Woman object which inherits from the Person object, or i could maybe store the information as an int, boolean or maybe even better as an Enumeration ? But i cant decide which is the "correct" way to do it. The Man and Woman object will be completly identical except for their type (how they are declared - new Man() and new Woman() ..). Or should I in this case go with the other option and store the information as an int/boolean/Enum in the Person object ? And is that how it is done when you have a value than can only be a certain different set of values ? Or something completly else ? There is no really difference as far as i can see, as i will either have to do checks like - if (myObj.Gender == "Man"), or if (myObj is "Man") of course i could do some overloading of the methods soo i dont even have the if else - like HandleThis(Man obj) and HandleThis(Woman obj). Maybe for the scalability, escpecially if it had been other information i had to store which could change by time it would probably be best to go with the inhertiance example. or maybe i should always go with that solution ? To some of you this might be a stupid question, but i cant really decide. Soo i hope someone can help me to tell me what is the "correct" way to do it and why. Martin Happy New Year everyone ! :)

        E Offline
        E Offline
        Ed K
        wrote on last edited by
        #3

        I'd think you need to look to whether the Gender object will have any responsibility. If you are handling any methods such as: if (myObj.Gender == "Man"), or if (myObj is "Man") you might want want to utilize the state or strategy patterns (GoF) instead. http://ootips.org/[^] or http://www.dofactory.com/Patterns/Patterns.aspx[^] ed ~"Watch your thoughts; they become your words. Watch your words they become your actions. Watch your actions; they become your habits. Watch your habits; they become your character. Watch your character; it becomes your destiny." -Frank Outlaw.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups