Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / What's the point of OOP?

Author
Message
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Oct 2011 09:42
The title pretty much says it: What's the point of Object Oriented Programming? I mean I've pretty much taught myself C and C++, and I don't see much in the way of advantages of C++ over C. In fact, it could be the contrary, since with C++ it doesn't seem to play nicely with multiple header files/code files that are included by multiple sources in the same project. (But that's another story I may bring up at another time.)
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 2nd Oct 2011 10:05
C++ is hard. It's a bona fide language, and it combines all of the memory management and low-level features of C with all the classes, polymorphism, inheritance, and naming features of OOP. That leads to one powerful language that's easy to mess up in, so learning OOP in C++ can be a big headache, and you need to know everything about what you're doing. I say this because I have a feeling you're not that great at C++ if you can't get header files to work. The whole purpose of the header/code structure is so that code is modular and it's easy to include stuff.

But... isn't operator overloading nice?


And how about all that scoping? If you program correctly, you can't even mess with stuff you're not supposed to. That's bug prevention at its finest!

And what about polymorphism? Yknow, where you can have a class Athelete, and a bunch of child classes like Runner, Swimmer, Pole-Vaulter, but you can still train any athlete, and you can pass a Runner to a function that's only supposed to accept an Athlete. Loading heirarchical data structures is super easy with this method.

I'm even jealous of the system that minecraft has. To create a new enemy, you really just have to extend a class, call most of its parent's methods, then add more behaviors as needed.

Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Oct 2011 10:16
What happened was the compiler kept griping that there were multiple definitions of a class in my project, but that was because I'd have the header file the class was in being included by two or three separate header files, which were in turn called by a single header file.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 2nd Oct 2011 11:18
Use preprocessor commands. Surround your header file with



Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Oct 2011 11:42 Edited at: 2nd Oct 2011 11:42
One of the main advantages is that it allows you to write very modular code.



Support a charitable indie game project!
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Oct 2011 15:32
I don't see what relevence OOP has to your problems with header files?

[b]
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Oct 2011 19:51
Quote: "I don't see what relevence OOP has to your problems with header files?"


That's not the only thing... there've been plenty of issues with it in the past.
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 2nd Oct 2011 20:00 Edited at: 2nd Oct 2011 20:14
There are numerous concepts behind OOP.

Textbook-wise the idea behind object oriented programming is to keep similar data AND the functions that operate on that data together. There'a also the orginizational design aspect that in theory makes it "easier" for teams of programmers to develop more sophisticated applications with a modular design which allows for quicker expanded functionality and maintenance throughout the life-cyle of said software.

Another concept is that of encapsulation. Say I code a class, I provide public member functions to access and manipulate the private data in that class. This serves multiple purposes. 1. You don't have to understand how my class works under the hood in order to use it. 2. By only allowing these functions to manipulate the private data, there is less likely-hood that the private data can be compromised or corrupted.

Now, If I am working on a project by myself and it happens to be a game.... I tend to throw out much of OO model. Nearly everything becomes public even the data. It just makes it "easier" and quicker to get things done. Basically I, and I'm sure many others, wind up stripping down classes until they pretty much serve the same purpose as structs in C. In fact, I find myself sticking more in-line with C structured programming, rather than full blown OOP whenever I can. The only time I believe I truly stuck to OOP philosophy was when I was in school and had to.

Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Oct 2011 20:06
Oops, I meant to ask...


How does that help solve the issue?

Sorry, my web browser was being stupid.
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Oct 2011 20:10
Thank you all for the help, and zenassem - I stuidied some C++ in school, and I shared a bit of the same philosophy. However in retrospect, with what Neuro Fuzzy mentioned about Minecraft and how baddies are programmed in it... he makes a good point of it. All I would need to do is reuse the same class for each baddy and make a child class from it to make it unique.
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 2nd Oct 2011 20:12 Edited at: 2nd Oct 2011 20:16
It prevents definitions from happening more than once, if they have been defined before. So if you have multiple files that include the same header or the header was included earlier in the file, the code is not inserted multiple times.

(There is a more technical answer.)

Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 2nd Oct 2011 20:31
Thanks!

As much as I hate to say it... DBPro isn't playing so nicely with me trying to utilize my own file formats for animation, so I might have to switch to C/C++.

Login to post a reply

Server time is: 2025-05-20 19:26:47
Your offset time is: 2025-05-20 19:26:47