|
|
|
|
|
|
|
As an example, computing the average salary of every employee of a company is a rather complex task. You can, however, break it down into these subtasks: |
|
|
|
|
|
|
|
|
1. Find out what each person earns. |
|
|
|
|
|
|
|
|
2. Count how many people you have. |
|
|
|
|
|
|
|
|
3. Total all the salaries. |
|
|
|
|
|
|
|
|
4. Divide the total by the number of people you have. |
|
|
|
|
|
|
|
|
Totaling the salaries can be broken down into: |
|
|
|
|
|
|
|
|
1. Get each employee's record. |
|
|
|
|
|
|
|
|
3. Add the salary to the running total. |
|
|
|
|
|
|
|
|
4. Get the next employee's record. |
|
|
|
|
|
|
|
|
In turn, obtaining each employee's record can be broken down into: |
|
|
|
|
|
|
|
|
1. Open the file of employees. |
|
|
|
|
|
|
|
|
2. Go to the correct record. |
|
|
|
|
|
|
|
|
3. Read the data from disk. |
|
|
|
|
|
|
|
|
Structured programming remains an enormously successful approach for dealing with complex problems. |
|
|
|
|
|
|
|
|
Yet, there are problems. The separation of data from the tasks that manipulate the data becomes harder and harder to comprehend and maintain as the amount of data grows. The more things you want to do with that data, the more confusing it becomes. |
|
|
|
|
|
|
|
|
Procedural programmers find themselves constantly reinventing new solutions to old problems. This is often called reinventing the wheel and is the opposite of reusability. The idea behind reusability is to build components that have known properties and then to be able to plug them into your program as you need them. This is modeled after the hardware worldwhen an engineer needs a new transistor she doesn't usually invent one; she goes to the big bin of transistors and finds one that works for what she needs or perhaps modifies it. Until object-oriented programming, there was no similar option for a software engineer. |
|
|
|
|
|
|
|
|
New Term: The essence of object-oriented programming is to treat data and the procedures that act upon the data as a single objecta self-contained entity with an identity and certain characteristics of its own. |
|
|
|
|
|