• Advertisement

Archived

This topic is now archived and is closed to further replies.

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

This topic is 5153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement