Computer World. Матросова Т.А. - 99 стр.

UptoLike

Составители: 

98
OOP presents an approach to programming that allows programmers to think in
terms of objects, or things, much like people think of things in the real world. Using
OOP techniques, a programmer can focus on the objects that naturally make up a
system, rather than trying to rationalize the system into procedures and data. The
OOP approach is a very natural and logical application of the way humans already
think.
The benefits of OOP go beyond easing the pain of resolving real world problems
in the computer domain. Another key issue in OOP is code reuse, when you
specifically design objects and programs with the goal of reusing as much of the code
as possible, whenever possible. Fortunately, it works out that the fundamental
approaches to OOP design naturally encourage code reuse, meaning that it doesn't
take much of an extra effort to reuse code after you employ standard OOP tactics.
The OOP design approach revolves around the following major concepts:
• Objects
Classes
Encapsulation
Messages
Inheritance
To understand how you can benefit from OOP design methods as a game
programmer, you must first take a closer look at what a game really is.
Think of a game as a type of abstract simulation. If you think about most of the
games you've seen or played, it's almost impossible to come up with one that isn't
simulating something. All the adventure games and sports games, and even the far-
out space games, are modeling some type of objects present in the real world (maybe
not our world, but some world nevertheless). Knowing that games are models of
worlds, you can make the connection that most of the things (landscapes, creatures,
and so on) in games correspond to things in these worlds. And as soon as you can
organize a game into a collection of «things,» you can apply OOP techniques to the
design. This is possible because things can be translated easily into objects in an OOP
environment.
Look at an OOP design of a simple adventure game as an example. In this
hypothetical adventure game, the player controls a character around a fantasy world
and fights creatures, collects treasure, and so on. You can model all the different
aspects of the game as objects by creating a hierarchy of classes. After you design the
classes, you create them and let them interact with each other just as objects do in real
life.
The world itself probably would be the first class you design. The world class
would contain information such as its map and images that represent a graphical
visualization of the map. The world class also would contain information such as the
current time and weather. All other classes in the game would derive from a
positional class containing coordinate information specifying where in the world the
objects are located. These coordinates would specify the location of objects on the
world map.