Object State and the Object's Interface
Design Process Example: Bank Account
Design Process Example: Bank Account Applet
OOP takes ADTs one step further. It actually allows you to organize your entire solution as a collection of types, known as classes, where each class defines both data and operations. Minimally, classes provide an excellent tool for constructing ADTs. They provide language support allowing the programmer to say, "These operations are designed to be used with this type of data."
Thus, in a given problem statement, non-OOP (such as procedural programming) concentrates on verbs (procedures) whereas OOP concentrates on nouns (objects), and the verbs associated with them..
But, as you know, there are many things about certain classes of objects that you can't see from the outside. These are their hidden attributes. We can determine the hidden attributes of a class of objects, by considering their behaviors. For example, when a car is driving, its speed is very important -- especially, for example, on heavily traveled roads. The same is true of its direction of travel. And, depending on the type of program we are writing, it might also be important to know more esoteric details, such as the speed of the engine measured in RPMs. And, of course, we wouldn't want to neglect one very important property -- the amount of fuel remaining in the car.
By carefully considering what objects do, what they need to do it, and how we otherwise describe them, we can determine the behaviors, hidden attributes, and visible attributes of different classes of objects.
Writing Java programs using the Object-Oriented approach is nothing more than identifying and describing the behaviors and attributes of objects.
For example, one operates a car by using the gas pedal, the brake pedal, and the steering wheel. Even the best among mechanics wouldn't consider driving a car, by manipulating valves, gears, and pulleys from under the hood. Although those items exist, and are essential parts of the automobile, they are only designed to be manipulated by other parts of the automobile.
There are private aspects of a class that, much like the internals of a car, are designed only to interact with other parts of the car. And, there are also public aspects of the objects that are visible to, and available to, the users of the object -- for example, the steering wheel.
When we hide certain properties of a class from public view, by making them private, this is sometimes known as information hiding. It is important however, to remember that Java allows us to specify both private data elements and also private behaviors.
我的英文是两万字的阿,可是只能贴3000,郁闷