how to code in a correct OO way using C++

Started by
5 comments, last by EvilKind 20 years, 3 months ago
I purchased the book Programing Role Playing Games with DirectX. The classes are structured into large core files for example graphics_core, sound_core, etc. I want to write my game code in an OO way. What I would like to know is how correct is the example code to begin with? I have attemped to split the classes into separate files, for example light class goes in its own .h and .cpp. Can you use typedef structures or structures, forward declaring in an OO approach as there is a fair few in this book code or is their anything else I should look out for in the provide code? I have not been aware of using anything like these in the language Eiffel. I have learned OO using Eiffel so now I want to make the change to C++ and are using the provided book code to assist. Could anyone give me any advice on not what to do or use if I want to code in a correct manor. Thank you for your time!
I got 2 books, one on game programming and another on miracles so I can understand.
Advertisement
Object Oriented code is just code that is inclined to using objects. There are lots of ways to go about doing it. I''ll bet this book would be a great place to look.

Not sure about the code you''re asking about
There is no 'correct' way. There's a plethora of design patterns and architectural strategies that are suitable for different needs. Some of the commonly accepted best practices really are not best for every situation. Then there's always personal preference, usually obtained through experience. What one programmer may preach another may shun.

Ultimately the best you can do is read texts on object orientation, browse freely available source code, and experiment. Eventually you'll pick up your own preferences and gain some insight into the strengths and weaknesses of all of the options available. Besides, if there were a 'correct' way then all code would be pretty much the same, and there would probably be many fewer C++ programmers around.


[edited by - aldacron on January 14, 2004 1:22:12 PM]
One approach to object oriented programming is to pretend you''re writing java. That is, have folders for different packages, mimic interfaces by creating classes with only pure virtual functions, only allow 1 non interface class for inheritance(and arbitrarily many interfaces). You can also get clever with namespaces for packages and use RTTI for the java instanceof operator.
Hey I got that book too. I havent read all the way through yet. How much did it help you, I''d like to know.
You can leave and beat the traffic or you can stay and beat your meat.Blink 182
Don''t you just hate it when you get your password wrong and you have to retype everything. I do so I''ll keep it short now.

Dransic - best book I have got yet, stick with it.

Funkymunky - Is that book really going to help now or is it just a good book? I got 4 months to write a 3D 1 level demo in OO. Do I need another book?
I got 2 books, one on game programming and another on miracles so I can understand.
quote:Original post by EvilKind
Don''t you just hate it when you get your password wrong and you have to retype everything. I do so I''ll keep it short now.



yeah, it''s happened to me once and it was a particularly long post too so you can imagine the frustration I was in when this happened. So from now on in all my post I always do ctrl-a, ctrl-c before posting.

--{You fight like a dairy farmer!}

This topic is closed to new replies.

Advertisement