This article is excerpted from:
Java Basics
Object-Oriented Design Philosophy: Consider
1. What objects and classes are involved in the problem domain?
2. Methods and attributes of classes and objects
3. Relationships between objects, classes, and classes
Concepts of objects and Classes
Object: The description of the thing in the problem domain in computer language. The object uses attribute (static) and method (dynamic)
State) to distinguish things
Class: an abstract concept used to describe objects of the same class. Class defines the static
State and dynamic attributes
A class can be seen as a template of an object, and an object can be seen as a specific instance of a class.
Relationships between classes (objects)
Association relationship: the parameters of methods in a class are often another class. This is the weakest link.
Inheritance relationship: the relationship between XX is a YY. Indicates that xx inherits from YY. For example, if Golden Monkey is an animal
Is an inheritance relationship.
Aggregation: XX is a part of YY. The head is a part of a person, and the hand is a part of a person. Aggregation (loose coupling ):
The relationship between the captain and the team. Combination: the two are an inseparable part. The head belongs to a person and cannot be a brain
The bag belongs to both a person and that person.
Implementation relationship: the relationship between interfaces and implementation classes. For example, for the Shanghai class, there can be a lot of steps for this method.
Methods, such as driving and driving.