Object-Oriented Programming Primer
With Object-Oriented Programming (OOP), users are learning a programming language and a new way of thinking.
When learning a new language of any kind, Linguist.com says,
“You need to experience a language through lots of exposure before you can hope to learn it.”The same is true for object-oriented programming. The best way to learn OOP is to learn by immersing yourself in an environment, like Smalltalk, where you use objects all of the time. Object orientation is simply a way of thinking about and modeling the real world.
In the object-oriented view of programming, standard computing concepts and data structures, such as control-of-flow, are abstracted and handled differently. Instead, OOP focuses on simulating the real world.
A developer uses objects to model real-world entities. Each object is intelligent and knows how to interact with other objects. With this approach, program design becomes relatively easy, because there is a direct correspondence between an object and its real-world counterpart, and you can bring all your real-world knowledge to bear. In fact, this approach allows you to focus more on the problem domain and less on computing-environment issues, such as memory management.
- An object is a combination of instance variables that describe the object’s data, and methods that describe the object’s behavior. In other languages, variables are comparable in certain respects to attributes, and methods are analogous to procedures.
- Objects are intelligent—you can anthropomorphize (attribute human characteristics or behavior to them).
- To request data or an action from an object, you must send a message to it. If the object understands the message, it activates the appropriate method. So, objects communicate similarly to humans!
- The internal data elements of an object are not directly available to other objects. Other objects must always use messages to ask the object for its data. This is called encapsulation.
- How an object interacts with the outside world is called its behavior. The object’s tasks and responsibilities determine its behavior. Sometimes an object will delegate a task to another object to avoid having to remember too much. A distributed design using responsibility and delegation is a good way of dealing with complexity and is one of the hallmarks of an object-oriented approach.
- When designing an object, a developer concentrates on its behavior and interaction with other objects, not on its internal structure.
- An object-oriented system consists of a group of objects sending messages to each other.
In summary, good object-oriented design is based on the real world. Objects map to entities in the real world. An object-oriented system is thus a simulation of some aspect of the world.
“I made up the term object-oriented. …” – Alan Kay