Consider we have two classes Line
and Point
which class Line uses class Point
as below:
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
and
public Class Line
{
private Point start;
private Point end;
...
}
I was wondering which of the constructors below are better for class Line due to OOP principles?
public Line(Point start, Point end)
{
this.start = start;
this.end = end;
}
or
public Line(int startX, int startY, int endX, int endY)
{
start = new Point(startX, startY);
end = new Point(endX, endY);
}
Definitely the first one. It is higher-level, the intent is clearer, it is more concise, and it is more maintainable with respect to changes to the Point class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With