[Please do not mail me a copy of your followup]
Start with SOLID principles of object oriented design:
<
http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)>
Some of the stuff you already mentioned falls under SRP.
n...@notvalid.com spake the secret code
<Dylcw.939137$9I4.7...@fx35.am4> thusly:
>So all of this I think I understand. My main question is that should I
>put all the functions to be as member functions of classes or global
>functions inside corresponding class header? I know we should avoid
>member functions, but what would be a good rule here which ones to make
>global functions and which ones members?
The general advice is to make things members that must be members. If
something can be achieved outside a member function, then make a free
function that achieves it.
By this guideline, std::string should not have find_first_of as a member,
since the algorithm std::find_first_of already covers the cases handled
by the member functions. Convenience functions that delegate to the
algorithm instead of methods could have been written. std::string would
have far fewer methods without any loss in performance if this advice
had been followed for std::string.
Its easier to make them
>members... Almost all of them are using private members, so is it just
>best to make them members even though then I get a lot of member
>functions, like 10-15?
My advice would be first to split your monster class into a network of
cooperating classes that each follow single responsibility principle.
Once you do this, clumps of methods tend to move together and you'll
find that the number of methods on any single class goes down.
>Also as you can see there are very many member
>variables as well... should I put all of them inside Game and Graphics
>classes, or group them into new structures?
Many member variables are also a general indicator that your class has
too many responsibilities. Look for clumps of member variables and
methods that go together -- for instance a group of methods that access
a clump of member variables but none of the other variables. This is
a candidate for a new class that has a single responsibility and
encapsulates those related member variables. Don't be afraid of small
classes that represent one single well-defined responsibility. (Think
of something like a two-dimensional point class.) Identify "value
types" in your code -- things like string, Point2D, etc., that don't
exhibit polymorphism or abstract interfaces. A common example is a
Money class that represents some specific quantity of money in a
particular currency.
For games, try to separate behavior (game play) from graphics (rendering).
Some articles on refactoring for C++ that may give you inspiration:
<
http://legalizeadulthood.wordpress.com/category/refactoring/>
--
"The Direct3D Graphics Pipeline" free book <
http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <
http://computergraphicsmuseum.org>
The Terminals Wiki <
http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <
http://legalizeadulthood.wordpress.com>