Classes

Hi
I want to build some objects that have a little difference between them. But i wonder how would i do it - 1. build a class with some variables and build objects out of him, or - 2.build class for each object, with the functions dedicated to this 'only one' object.
Is there any difference between the two methods? It is clear that its much more simple to build a class for each object, and define the functions for this object in the class. What is the profit of make one class, and inherit many objects out of it, make it complicated to implement different functions for each object.
Someone?
It's all about the desired behavior of the object.

If the objects will behave the same way, just with different variables, then it's probably best to use one class and have the variables.

If the objects will have distinctly different behavior, then it's probably best to separate them into different classes with a common base class.


For example... if you find yourself doing this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void MyClass::AFunction()
{
  if(object_is_class_1)
  {
    // do something
  }
  else if(object_is_class_2)
  {
    // do something else
  }
  else
  {
    // do something else
  }
}


Then it's probably best to split it up into different classes.


Can you provide more details on exactly what your class(es) will be doing?
Topic archived. No new replies allowed.