Sign in to follow this  
MatiasMunk

[C++/A5] OOP Code

Recommended Posts

You identify state that you can store somewhere, and give it some kind of name that describes what it is. Write some methods for that object. Why would you want to take some pre-existing code and apply OOP to it? Especially if you just have some functions calls to an API and that's it.

 

I imagine you shouldn't even really worry about what is or isn't OOP and just try to write code that makes sense to you. I hope this helps!

Share this post


Link to post
Share on other sites

Object orientation is a modelling technique. The obvious candidate for modelling might be the buttons. Right now, buttons are an implicit concept in your program, a consequence of the hard coded logic. If you stripped out the comments, it might not even be clear that there are buttons. An alternative way to write this is to create a Button class or structure, and write code that displays and manipulates Button instances.

 

Why don't you show us what you've tried?

Share this post


Link to post
Share on other sites

Because the code is not even done Randy. I am planning to add more to it, and it will just become a mess on the long-term.

Because I would like to take the time and learn OOP, as I've heard it makes life easy.

Also I plan on having people helping me with code in the future, as a team.

 

Thank you Rip-off, I'll try and recreate what I tried before, and post it here :)

Share this post


Link to post
Share on other sites

Because the code is not even done Randy. I am planning to add more to it, and it will just become a mess on the long-term.

Because I would like to take the time and learn OOP, as I've heard it makes life easy.

Also I plan on having people helping me with code in the future, as a team.

 

Thank you Rip-off, I'll try and recreate what I tried before, and post it here smile.png

 

The code not being done is not a problem, it can actually be a *good* thing. Should you postpone changing your approach from procedural to object-oriented until later, it's quite possible you'll have to tackle a number of problems (e.g. tight coupling, global variables, walls of code) on top of implementing your design.

 

Saying that OOP makes life easy is a bit superficial. Nothing prevents you from coming up with an object-oriented design that's poorly abstracted and tightly coupled. Even if your design is good, you could end up writing a really bad implementation. I'd say that, if you come up with a sound design and follow good practices, you can write object-oriented code that is easier to extend and maintain than procedural code, and be more productive - but it's still hard work.

 

EDIT: About your question, I think you can learn much from the design and implementation of the source code of the book SFML Game Development. I took a look at your code, and I think you can use the code from the "01_Intro" chapter as a starting point.

Edited by georger.araujo

Share this post


Link to post
Share on other sites

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