Skip to content

Page383

Object-Oriented Design and Programming

Object-oriented design and programming uses an object metaphor to design and write computer programs. Our bodies are comprised of objects that operate independently and communicate with each other. Our eyes are independent organs (objects) that receive input of light, and send an output of nerve impulse to our brains. Our hearts receive deoxygenated blood from our veins and oxygen from our lungs, and send oxygenated blood to our arteries. Many organs can be replaced: a diseased liver can be replaced with a healthy liver. Object-Oriented Programming (OOP) replicates the use of objects in computer programs. Object-Oriented Design (OOD) treats objects as a higher-level design concept, like a flowchart.

Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP) changes the older structured programming methodology, and treats a program as a series of connected objects that communicate via messages. Object-Oriented Programming attempts to model the real world. Examples of OOP languages include Java, C++, Smalltalk, and Ruby.

An object is a “black box” that is able to perform functions, and sends and receives messages. Objects contain data and methods (the functions they perform). The object provides encapsulation (also called data hiding): we do not know, from the outside, how the object performs its function. This provides security benefits: users should not be exposed to unnecessary details. Think of your sink as an object whose function is washing hands. The input message is clean water; the output message is dirty water. You do not know or care about where the water is coming from, or where it is going. If you are thinking about those issues, the sink is probably broken.

Cornerstone Object-Oriented Programming Concepts

Cornerstone object-oriented programming concepts include objects, methods, messages, inheritance, delegation, polymorphism, and polyinstantiation. We will use an example object called “Addy” to illustrate the cornerstone concepts. Addy is an object that adds two integers; it is an extremely simple object, but has enough complexity to explain core OOP concepts. Addy inherits an understanding of numbers and math from his parent class (the class is called mathematical operators). A specific object is called an instance. Note that objects may inherit from other objects, in addition to classes.