Java Object-Oriented Analysis

Source: Internet
Author: User

Java 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)




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.