考虑我们有两个类
Line
和Point
,其中类Line
如下使用类Point
:public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
并且
public Class Line
{
private Point start;
private Point end;
...
}
基于面向对象编程原则,我在思考以下哪种构造函数对于Line类更好?
public Line(Point start, Point end)
{
this.start = start;
this.end = end;
}
或者
public Line(int startX, int startY, int endX, int endY)
{
start = new Point(startX, startY);
end = new Point(endX, endY);
}