Java object-oriented analysis, Object-Oriented Analysis
1. An important experience of object-oriented design:
Anyone who owns the data provides external methods to operate the data.
2. Typical object-oriented Cases
1. Draw circles on the blackboard
Objects involved: person, blackboard, and circle
Which object should we use to draw circles?
Because the circle method involves the center and radius of Private member variables, the circle method should be provided by the circle.
2. train drivers brake urgently
Objects involved: drivers and trains
Should the brakes be on the driver or on the train?
The brake action involves engine flameout, clutch, and wheel lock. Therefore, this method should be provided by the train.
3. The salesperson collects statistics on the amount of small tickets sold
Objects involved: salesclerk and ticket
Should the statistical method be provided by the salesperson or the bill? (Ticket)
3. Object-oriented Design Questions
1. Move the ball from one end of a rope to the other
public class Point {private float x;private float y;public Point(float x, float y) {this.x = x;this.y = y;}}class Rope {private Point start;private Point end;public Rope(Point start, Point end) {this.start = start;this.end = end;}public Point nextPoint(Point currentPoint) {return null;}}class Ball {private Rope rope;private Point currentPoint;public Ball(Rope rope, Point startPoint) {this.rope = rope;this.currentPoint = startPoint;}public void move() {}}
2. Two stones are ground into a stone knife, which can cut trees, cut into wood, and make wood into chairs.
Object: Stone StoneKnife Tree Material Chair
StoneKnife s = KnifeFactory. createKnife (stone)
Material m = StoneKnife. cut (tree)
Chair c = ChairFactory. makeChair (material)
Is java object-oriented or process-oriented?
JAVA is object-oriented.
The differences between the two are as follows:
Process-oriented is to analyze the steps required to solve the problem, and then use functions to implement these steps Step by step. You can call these steps one by one.
Object-oriented refers to dividing a problem transaction into various objects. The object is created not to complete a step, but to describe the behavior of a thing in the whole process of solving the problem.
For example, wuziqi, the process-oriented design idea is to first analyze the problem steps: 1. Start the game, 2. sunspots first, 3. Draw the screen, 4. Determine whether to win or lose, 5. Turn to the white, 6. Draw a picture. 7. Determine whether to win or lose. 8. Return Step 2. output the final result. The above steps are implemented using separate functions, and the problem is solved.
The object-oriented design solves the problem from another idea. The entire Wuzi game can be divided into 1. Black and white sides. The two sides act exactly the same way. 2. The board system is responsible for drawing pictures. 3. The rule system is responsible for determining such as foul and winning or losing games. The first type of object (Player Object) is responsible for accepting user input, and notifying the second type of object (board object) of the changes in the layout of the pawns, when the checker object receives the I change of the pawns, it is responsible for displaying this change on the screen. At the same time, it uses the Third Class Object (rule system) to determine the game board.
It can be seen that object-oriented is to divide the problem by functions rather than steps. The same is drawing board games. Such behavior is distributed across multiple steps in the process-oriented design, and different drawing versions may appear, because the designers usually take into account the actual situation for a variety of simplification. In the object-oriented design, plotting can only appear in the chessboard object, thus ensuring the unity of drawing.
The unified functions Ensure the scalability of the object-oriented design. For example, I want to add the regret function. If I want to change the process-oriented design, I need to change the input, judgment, and display steps, even steps must be adjusted on a large scale in sequence. If it is object-oriented, you only need to modify the chessboard object. The checkerboard system saves the chess spectrum of both sides of the black and white, and simply backtrack the Board object. The display and rule judgment do not need to be taken into account, at the same time, the calling sequence of the object function is not changed, but the changes are only partial.
For another example, I want to change this wuziqi game to go game. If you are looking at process design, the rules of wuziqi are distributed in every corner of your program. If you want to change the rules, you should rewrite them. But if you are an object-oriented design, you only need to modify the rule object. Isn't the difference between wuziqi and go rules? (Of course, the size of the Board seems to be different, but do you think this is a problem? You just need to make a small change in the checker object .) The general steps of playing chess are not changed from the object-oriented perspective.
Of course, to achieve changes, only the design personnel must have sufficient experience. Using objects cannot guarantee that your program is object-oriented, A beginner or a very poor programmer may be able to face the process with a virtual object-oriented approach. The so-called object-oriented program designed in this way is difficult to have good portability and scalability.
What Is Object-Oriented in java? It is best to understand it by yourself.
Object-oriented, in fact, is to convert the real world into data, and then package it into an object...
Height, weight, and shape are data. We call it human beings...
That is, public class Human {}.
Then, when the data in this class is assigned a value, what we get is not a specific type, but a specific person.
This is called an object.
That is, new Human (...);