C# - Basic template - Program organization

Discussion in 'Programmer's Corner' started by atferrari, Jan 12, 2009.

  1. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    C# language.

    I imagine a zoo with lots of animals. To deal with their info I organized them somehow.

    They all:

    Sleep xx hrs / day.
    Eat food xx Kg / week.

    Some of them:

    bellow, cheep, howl or whatever.

    are he and some are she.

    are covered by feathers, leather, bristles or ...

    have names like "Jack", "Tweety", "Pirate" or no name at all.

    walk, run, fly or ...

    I would like to be able to do, as an example:

    Compare some felines with some birds to see how much more food each one eats per month.

    For a specific type, let's say siamese cats, to know they gender and names if any.

    What type of cow sleeps more hours / month.

    That is, I need, in some cases to pass / retrieve numeric data, so some of the classes are not all static.

    My comments:

    I am not asking for code, of course. It is that I find difficult to organize in my mind kind of a template more or less complete and somehow more complex than most of the examples allow to expect (given online by Microsoft, I mean).

    I realized that once I grasp how to organize namespaces and classes, I could walk faster by myself.

    I am learning just by reading online. Tutorials put their accent in this or that but it seems that what I am asking here is almost taken for granted.

    I have no previous experience with C, C++. Just that old BASIC from 25 years ago and assembler for PIC micros which I write fluently.

    My questions:

    a) Is this organization reasonable (classes inside classes inside classes), or there is a better way to work with this?

    b) Could be that I would need another namespace besides this one only? Maybe two, three or more? (Totally clueless about that!)

    c) Where should I locate Main? Inside the class XXXX_catalogue or...?

    d) Am I too off subject, maybe?

    Code ( (Unknown Language)):
    3. namespace The_zoo_next_door
    4. {
    5.     class MaybeIncongruent_animals_catalogue
    6.     {
    7.         class bovine
    8.         {
    9.             class Angus
    10.             { }
    11.             class Hereford
    12.             { }
    13.             class Holando
    14.             { }
    15.         }
    16.         class feline
    17.         {
    18.             class domestic
    19.             {
    20.                 class siamese
    21.                 { }
    22.                 class maltese
    23.                 { }
    24.             }
    25.             class wild
    26.             {
    27.                 class tiger
    28.                 { }
    29.                 class bobcat
    30.                 { }
    31.                 class cheetah
    32.                 { }
    33.             }
    34.         }
    35.         class birds
    36.         {
    37.             class domestic
    38.             {
    39.                 class chicken
    40.                 { }
    41.                 class goose
    42.                 { }
    43.                 class canary
    44.                 { }
    45.             }
    46.             class wild
    47.             {
    48.                 class robin
    49.                 { }
    50.                 class condor
    51.                 { }
    52.                 class falcon
    53.                 { }
    54.             }
    55.         }
    56.         // Is this the right place?
    57.         static void Main(string[] args)
    58.         { }
    59.     }
    60. }
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    Maybe. The hierarchy you're thinking of follows the pattern by which animals and plants are divided, with Kingdom, Family, Genus, and Species and all. That's the way Linnaeus organized things, but isn't the easiest to work with in computer databases, which tend to be pretty flat tables, with multiple rows and columns.

    Instead of a monster class with classes nested inside classes, and so on, you might consider starting with one generic class with properties/attributes all the zoo animals share:
    • how long they sleep per day (a 24-hour period)
    • how much they eat per day
    • the animal's gender, although I suppose it's possible for some animals to not have a gender -- biology isn't my strong suit
    • the animal's name, like "Tweety" or whatever. This property could be null for an animal that doesn't have a name
    • skin covering -- fur, feathers, none,...
    • sound the animal makes...
    • how the animal moves ...
    • etc.
    If you want a database that's searchable, you will need attributes for genus, species, and all that.
    I don't think so. One namespace would cover it, I think, unless there's a need for more.
    Outside the classes. The main function would have its own instance(s) of animals to work with.
  3. atferrari

    Thread Starter AAC Fanatic!

    Jan 6, 2004
    Gracias for the reply Mark!