Week8 - Chapters 8 9 10 Object-Oriented Programming As you...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Object-Oriented Programming As you know, all computer programs consist of two elements: code and data . Furthermore, a program can be conceptually organized around its code or around its data. Some programs are written around “what is happening” and others are written around “who is being affected.” The 1 st way is called the process-oriented model since these kinds of programs are characterized as a series of linear steps (i.e., code). Procedural languages such as Pascal and C employ this model. To manage increasing complexity, the 2 nd approach, called object-oriented programming, was conceived. Here, a program is organized around its data (ie., objects) and a set of well-defined interfaces to that data. Abstraction An essential element of OOP is abstraction. Humans manage complexity through abstraction. For example, people do not think of a car as a set of tens of thousands of individual parts. Instead, they think of it as a well-defined object with its own unique behavior. This abstraction allows people to use a car to drive to the grocery store without being overwhelmed by the complexity of the parts that form the car (i.e., we can ignore the details of how the engine, transmission, and braking systems work and we are therefore free to utilize the object as a whole). A powerful way to manage abstraction is through the use of hierarchical classifications. From the outside, the car is a single object. Once inside, you see that the car consists of several subsystems: steering, brakes, sound system, seat belts, heating and so on. Each of these subsystems is made up of more specialized units. For instance, a sound system consists of a radio, a CD player, and a tape player. The complexity of the car consists of hierarchical abstractions. Class definitions in Java provide a mechanism for creating abstractions. The data fields capture the essential attributes of entities being represented. Methods provide a mechanism for manipulating those attributes. Encapsulation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Abstraction allows the key parts of a class to be represented, but does not describe how the data associated with a class is kept or accessed. Rules must be established for how the data can be manipulated and who is allowed to do it. This control is provided through encapsulation . Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. It builds a wall around an object’s private data, allowing users of an object to access its data only through the public methods of the object’s class. One way to think about encapsulation is as a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper. Consider the transmission on an auto. It encapsulates hundreds of bits of information about your engine. The user has only one method of affecting this complex encapsulation: moving the gearshift lever. The gearshift is a well-defined interface to the transmission.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 19

Week8 - Chapters 8 9 10 Object-Oriented Programming As you...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online