First, the object-oriented five basic features:
1. All things are objects. treats an object as a peculiar variable, he can store the data, and can require it to perform operations on itself.
2. A program is a collection of objects that they tell each other to do by sending a message.
3. Each object has its own storage that is composed of other objects. in other words, you can create a new type of object by creating a package that contains an existing object.
4. No object has its type. The most important feature of each class is "what message can be sent to it".
5. All objects of a particular type can accept the same message.
Second, when trying to develop or understand a program design, one of the best ways is to think of the object as a "service provider." The program itself will provide services to the user, and he will do so by invoking the services provided by other objects. Your goal is to create (or preferably find in an existing code base) a range of objects that provide the ideal service to solve the problem. One way to get started is to ask yourself, "What kind of object can solve my problem if I can pull it away from the surface?" ”。
Thirdly, when establishing new classes, the combination (HAS-A) should be considered first.
To decide whether to inherit is to determine whether is-a can be used to describe the relationship between classes and to make it practical.
Learn Java Programming ideas Introduction to the first chapter object