Object-oriented programming (OOP) is standard fare for the typical programmer in today's workplace, especially in the games industry. However, the first question all beginning game programmers ask is: 'What programming language should I learn?' I always respond with some useful information about a language (typically C# and XNA) and always include something suggesting them to look at a book or set of websites about object oriented techniques.
Why do I suggest this? Well, not only will it make them a more solid programmer, but it will take some of the redundancy (and headaches) out of their work. Also, the high amount of OOP in the workplace is relatively new (which is why we are seeing company after company creating large-scale system-replacement projects). If you have even a slight passion for creating object oriented code, you'll be a valued asset to anywhere you work. I don't know how many times I've been commended for my desire to rework non-OOP code.
What is OOP?
Object-oriented programming (OOP) is a programming paradigm that puts an emphasis on several concepts to create reusable and easily extendable code. The core of OOP focuses on objects (hence object-oriented programming). Other techniques in OOP include the basics such as classes and their members and goes through more advanced techniques like polymorphism. Don't worry if you don't know what most (or any) of these are, we will discuss everything just mentioned and give simple, game-development focused examples (polymorphism will be in a future article).
Classes & Objects
Classes are one half of the core concept behind objects. In the most simple sense of the definition, classes are the blueprints for an object. Well that's great and all, but what the heck is an object? An object is an instance of something, typically something definable in the real-world. Great, two definitions in and you're already confused. Let's take a real-world example of classes and objects before we get into a game-development example.
How did your house or work building get developed? Well, first someone drew up a blueprint of a house, defining things like where the bathrooms are and where the stairs will be. After the blueprint was finished, the construction team came in a built the house based on the blueprints. In this case the blueprints for the house is the class, and the finished, physical house is the object.
In programming, we call the house an instance of the class (because it is a physical version of the blueprint). Let's combine all these concepts into an example using the Gran Turismo series.
Gran Turismo, as most gamers know, is a racing game. As such, it features cars (shocker, I know). It wouldn't make sense to go through the entire process of writing up a car from scratch and then having to redevelop the entire thing would it? No. That's why we come up with a blueprint for a car. Then we can create multiple cars off that blueprint and suddenly, voila, we have a screen filled with cars:
Comments
Post a Comment