First of all, according to the needs of the analysis, combined with object-oriented design, for traffic light management system, to determine the change in the lamp, when the car began to go, the first need to put it
To abstract, and the most important experience in cotton thread design is: Who owns the data and who provides the means to manipulate the data.
Create a road class, he's got a car. This attribute (ArrayList), and the Java concurrency Library that he uses, allows him to generate a car every second (since it uses internal classes, when the inner class accesses the properties of the external class, the implementation must be final, or use Class name. This. property name to access
One of the more important is when the lamp from red to green, he wants to inform the next to say which light is green, the next time to change, so cycle.
In addition, 12 traffic lights are designed as enumerations, each of which is an instance object of an enumeration, and a valid short line of code.
Some aspects of object-oriented design:
A typical case of object-oriented design
1, people on the blackboard to draw a circle
Objects: Person,blackboard,circle
Draw () Draw round This action is provided by WHO. Answer: Park
Because
Drae () {
X,y--> Radius This method has a center (x,y) Radius (RADIUS) that is the property of the garden.
}