C# - Basic template - Program organization

Thread Starter

atferrari

Joined Jan 6, 2004
4,767
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?

Rich (BB code):
namespace The_zoo_next_door 
{ 
    class MaybeIncongruent_animals_catalogue 
    { 
        class bovine 
        { 
            class Angus 
            { } 
            class Hereford 
            { } 
            class Holando 
            { } 
        } 
        class feline 
        { 
            class domestic 
            { 
                class siamese 
                { } 
                class maltese 
                { } 
            } 
            class wild 
            { 
                class tiger 
                { } 
                class bobcat 
                { } 
                class cheetah 
                { } 
            } 
        } 
        class birds 
        { 
            class domestic 
            { 
                class chicken 
                { } 
                class goose 
                { } 
                class canary 
                { } 
            } 
            class wild 
            { 
                class robin 
                { } 
                class condor 
                { } 
                class falcon 
                { } 
            } 
        } 
        // Is this the right place? 
        static void Main(string[] args) 
        { } 
    } 
}
 

Mark44

Joined Nov 26, 2007
628
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?
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.
b) Could be that I would need another namespace besides this one only? Maybe two, three or more? (Totally clueless about that!)
I don't think so. One namespace would cover it, I think, unless there's a need for more.
c) Where should I locate Main? Inside the class XXXX_catalogue or...?
Outside the classes. The main function would have its own instance(s) of animals to work with.
d) Am I too off subject, maybe?
No.
Rich (BB code):
namespace The_zoo_next_door 
{ 
    class MaybeIncongruent_animals_catalogue 
    { 
        class bovine 
        { 
            class Angus 
            { } 
            class Hereford 
            { } 
            class Holando 
            { } 
        } 
        class feline 
        { 
            class domestic 
            { 
                class siamese 
                { } 
                class maltese 
                { } 
            } 
            class wild 
            { 
                class tiger 
                { } 
                class bobcat 
                { } 
                class cheetah 
                { } 
            } 
        } 
        class birds 
        { 
            class domestic 
            { 
                class chicken 
                { } 
                class goose 
                { } 
                class canary 
                { } 
            } 
            class wild 
            { 
                class robin 
                { } 
                class condor 
                { } 
                class falcon 
                { } 
            } 
        } 
        // Is this the right place? 
        static void Main(string[] args) 
        { } 
    } 
}
 
Top