Link Bar

Home | Games | Programming | Tutorials | Donate | Legal (These are mostly empty right now. Placeholders!)

warning code

This website contains adult content.

Tuesday, March 20, 2012

Day 26: Object-Oriented Programming

So I pulled up a bunch of stuff to read on OOP over the weekend.  I started with Wikipedia's page on object-oriented programming, and when I got to methods, I thought, "Gee, this looks important.  Wonder what it is?"  New tab.  That article fairly swiftly mentions classes, so that meant another new tab.  And somewhere in there was a mention of UML, which term I did not recognize, so I checked it out for good measure.

Hmm... with the other pages I've got pulled up (introductory lessons for C++ from gillius.org, tenouk.com, and desy.de which looked interesting, then this from cplusplus.com and that from intap.net), this was starting to look suspiciously like a wiki walk.  I started with classes and read it all the way through, then back up to methods and finally into OOP generally.  Whuff, that's already quite a bit of reading.

What's more, it's informationally dense, too.  Check this out:

In a language that supports inheritance, an abstract class, or abstract base class (ABC), is a class that cannot be instantiated for it is either labelled as abstract or it simply specifies abstract methods (or virtual methods). Abstract classes specify virtual methods via signatures, that are to be implemented by direct or indirect descendents of the abstract class. Before a class derived, directly or indirectly, from an abstract class can be instantiated, all abstract methods of its parent classes must be implemented by some class in the derivation chain.
 - Wikipedia on abstract classes


Now, I had to read that a second time to really get it.  But now that I do, good Lord, is that last sentence important to remember!  And the whole thing is like this, pretty much, for a beginner like me.


I got to Chapter 3 in the tutorial at gillius.org and was referred to a page with information on dynamic memory allocation (covered way back in reg'lar C++, and now taken for granted in object-oriented C++) for not knowing about the "new" and "delete" commands.


And after more reading like this, it's becoming clear to me that OOP is much more complicated than I thought it would be (...surprise?).  I guess I'm back into a reading phase, then, since I'm not really sure quite how to start coding my objects.  And by "start," I mean how I want things to be organized in the grand scheme of things so that I know what classes I'll have and what individual objects will belong to what classes and so on, all of which it looks like I'll need to plan out in some manner of detail beforehand - oh, gosh, this means I need a Big Boy design document.  OK, so I guess that's the next step before I get objects into Hula, and then I can worry about instantiating the items in the game once I've got some classes & such described from which to draw when representing the game world.  Well, let's just start with one, like in Noob Game, and then blow it up to two, and then many, and we'll see where that takes me.


Oi, I love reading and learning and filling my brain with exciting new things... but this is tough sometimes!  Zach, things are certainly "spiralling out of control naturally," just like you said they would.

2 comments:

  1. the #1 most important thing about classes is that they help you organize your data into Things. A class is a definition of what a Thing is, saying what it is (its properties) and what it can do (its methods). All the abstraction and inheritance and friends and scope shit is really not important right at the beginning and you can pick that up as you go along.

    Just remember: define some Things, and then make some Things, and then have those Things do things.

    Also! I will get to your email later today; I've been extra busy at work (big surprise) due to deadlines and haven't had much free time at all.

    ReplyDelete
  2. Just to reiterate what Zach said in slightly different language (as I often find useful while learning), objects are simply information (data) collected together with behavior (methods). Methods are really just functions that run in the context of an object and so they have access to the data of that object.

    Things are made up of the details about them and the things they can do.

    A car (class) is something with properties (color, make, model, engine type, age) that can do things (open door, turn left, accelerate). This car (object of the class car) is a red 2012 Audi R8 with 5 gallons of gas that is parked in front of your house. By putting this key (object of class key) into the ignition of this car, I can start it (call the start engine method on the car object).

    ReplyDelete