Click here to Skip to main content
15,615,651 members
Articles / Programming Languages / C#
Posted 21 Feb 2011

Tagged as


4 bookmarked

Determine number of classes to be used

Rate me:
Please Sign up or sign in to vote.
3.20/5 (4 votes)
22 Feb 2011CPOL
Use XML representation of data to figure out object oriented design

This tip is especially for those friends who just started using OOPS concepts and are facing difficulty in determining number of classes to be used for any given scenario. I used this visual technique for getting a quick hint during days as a fresher so thought of writing about it.

For any scenario (given as requirement), try to visualize and draw its equivalent structure in XML format, through it you can at least have a better picture about classes needed.

E.g. We are trying to describe a zoo that can have number of animals and staff members:

    <Animal Name="Elephant">
      <Cage Number="102">
      <!-- Additional details -->
    <Animal Name="Lion">
      <Cage Number="104">
      <!-- Additional details -->
    <Keeper Name="Adam"></Keeper>

The corresponding classes will look like:

public class Zoo 
    public Collection<Animal> Animals { get; set; }
    public Collection<Keeper> Staff { get; set; }

public class Animal 
    public string Name { get; set; }
    public Cage Cage { get; set; }

public class Cage 
    public int Number { get; set; }

public class Keeper 
    public string Name { get; set; }

Now as per more clear needs, keep modifying XML inputs and correspondingly your classes.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralIt is not just the data that you deal with in the software t... Pin
OldWiseLlama28-Feb-11 18:25
OldWiseLlama28-Feb-11 18:25 
It is not just the data that you deal with in the software that determines the number of classes (or other units). I have found the following principles helpful in designing systems:
- (Single Responsibility)
- (Open-Closed)
- (Dependency Inversion)
- (Interface Segregation)

Although it might seem boring in school, drawing UML might also actually be helpful.
GeneralReason for my vote of 4 Good visual tip, thanks for sharing. Pin
joelcarroll28-Feb-11 12:45
joelcarroll28-Feb-11 12:45 
GeneralReason for my vote of 1 useless Pin
Manish K. Agarwal22-Feb-11 2:57
Manish K. Agarwal22-Feb-11 2:57 
GeneralRe: Thanks for the feedback. This trick is not for an experience... Pin
r verma22-Feb-11 14:18
r verma22-Feb-11 14:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.