Sign in to follow this  

How to use OO well

This topic is 4865 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 know there are many books on this, and I have already searched google, but I'm wondering if any of you know of any good resources and/or could just tell me yourselves some good object oriented practices my first and only programming language is C++, so I know about object orientedness (is that a word?) and how to implement it in the code, but I'm not sure if I'm using the concepts well...like just what to make classes and how to divide things, and things like that I think I sometimes try to split things too much...since I've only known C++, I try to make everything fit in a class...

Share this post


Link to post
Share on other sites
This book is meant to be good. The main thing to understand though(if coming from a procedural background), is that objects are SIMPLE. I say this because i used to try and make my classes overly complicated, i think procedural programming encourages you to think of more specific functions, but in oop it's more abstract functions.. if i'm making any sense :P

Share this post


Link to post
Share on other sites
It will come with experience, just keep writing programs and eventually they will become neater and neater and OO will be easier to implement. Also you might want to play around with a OO scripting/programming language. I learned somethings about OO from reading Python code.

Share this post


Link to post
Share on other sites
yes, one way I learn very well is with examples...does anyone know of any open-source oo programs that are well-written (so as to provide a good example)?

Share this post


Link to post
Share on other sites
I learn oop by learning smalltalk. I would recomend it as its a good starting point for oop but I guess there is most likely a book to follow thats easier. ahve you tried learning uml?

Share this post


Link to post
Share on other sites
look into UML m8 as most books on the subject teach good modelling processes. its not a programming lanuage more of a descriptive one and very handy for use in designing games.

Share this post


Link to post
Share on other sites
Since data changes more frequently than interfaces folks recommend you code to abstract interfaces which represent abstract concepts that won't change much. A car has an engine, what kind doesn't matter as long as user can start it. So some code in your codebase will code to the engine abs interface and then later you can change the engine to electric one for example and that part that uses the abs engine interface will still work and won't have to change. This reduces code maintenance.

The second thing is that you don't want to be pulling data out of an object and instead ask the object to act on its own data. This way that data is localized to one class and it isn't all over the codebase. Again simplifies code maintenance. The danger here is the creation of god classes by shoving every kind of data into one object so that other parts have direct access to that data. Sometimes you need to pull data out which is ok but go easy on it.

Also, objects should communicate among each other to do things. Some algos will be described by this communication. I like to use finite state machines for my tasks and for algos. They're easier to understand when written on paper as a state diagram. Look up www.objectmentor.com website for more ideas.

Share this post


Link to post
Share on other sites
A good thing to look into are patterns. I myself learned a lot about class design and class/module interaction from patterns.

I can recommend the Gamma on this subject, here's the url for it: Design Patterns

Also, you can try to google for "Programming Patterns". These are two sites that I've found and that look decent on first glance:
Patterns Link 1
Patterns Link 2

I hope that helps.

Share this post


Link to post
Share on other sites
Thanks for the advice everyone. I've started to read Thinking in C++ and I kind of like theory like that, so it's been helpful. I've also looked into UML, and that looks cool...

Share this post


Link to post
Share on other sites

This topic is 4865 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this