S
Stefan Ram
Assume you needed a class ColorPoint in Java:
class ColorPoint extends Position, Color;
. Would it be so bad to implement this using public fields
instead of classical delegation? Public fields:
class ColorPoint
{ public final Color color;
public final Position position; ... }
, usage:
point.color.r = 72;
point.color.b = 65;
point.color.c = 41;
point.position.x = 212;
point.position.y = 117;
. Classical delegation style:
point.setR( 72 );
point.setB( 65 );
point.setC( 41 );
point.setX( 212 );
point.setY( 117 );
. I only ask, because public fields usually are frowned upon
in OOP, but what would be the drawback here, especially when
those fields are final?
class ColorPoint extends Position, Color;
. Would it be so bad to implement this using public fields
instead of classical delegation? Public fields:
class ColorPoint
{ public final Color color;
public final Position position; ... }
, usage:
point.color.r = 72;
point.color.b = 65;
point.color.c = 41;
point.position.x = 212;
point.position.y = 117;
. Classical delegation style:
point.setR( 72 );
point.setB( 65 );
point.setC( 41 );
point.setX( 212 );
point.setY( 117 );
. I only ask, because public fields usually are frowned upon
in OOP, but what would be the drawback here, especially when
those fields are final?