Hi,
In am new here. Pardon my english, I'll try to do my best.
I don't know exactly how to title my question, neither how to formulate it, so I am just going to use a general example:
Imagine that in order to represent a mathematical world, I first create a "Space" class, that will contain secondary objects, such as "Point", "Line", etc.
Example 1: In order to know the distance between 2 Points, what would be the best choice :
Writing a method
distance(Point* a, Point* b)
in my class "Space" ?
OR
Writing a method
distanceTo(Point* b)
in my class "Point" ?
------
Example 2: I choose to give my "Line" class 2 parameters.
1 2
|
Point* _start;
Point* _end;
|
Again, what would be the best choice :
Writing a method
createLine(Point* a, Point* b)
in my class "Space" ?
OR
Writing a method
createLineTo(Point* b)
in my class "Point" ?
------
Examples like these go on and on...
This question can appear if you want to create a molecular simulation.
Should one put "Atom"
and "Bond" classes in the "Molecule" class, or put "Bond" in "Atom"
and "Atom" in "Molecule"?
In fact, my question is:
Which "level of deepness" is generally better?
-"Top" objects that contain many smaller, ones and own all the methods to make then interact?
-Objects inside objects inside objects?
Is there any theory about it, or is it just a personal choice?
Thanks in advance !