I suppose for some idiosyncratic value of "right."
In the Point example, the API that respects encapsulation would remain the same between the 2D and 3D versions, along with any code using it. The API with un-encapsulated data would have to change at every single place in the code where a Point was passed.
(In other words, the implementation details of Point have leaked out into the system at perhaps 100's of places. Avoiding this and decoupleing ourselves from implementation is precisely why we have encapsulation in OO.)
How this applies to color is left as an exercise to the student.
How this applies to color is left as an exercise to the student.
This is what I'd like to hear. Cocoa has NSPoint, which is exactly what you're talking about, for points. And NSColor is already a kind of the basic object for colors. Do you really need more primitive types for this?
In the Point example, the API that respects encapsulation would remain the same between the 2D and 3D versions, along with any code using it. The API with un-encapsulated data would have to change at every single place in the code where a Point was passed.
(In other words, the implementation details of Point have leaked out into the system at perhaps 100's of places. Avoiding this and decoupleing ourselves from implementation is precisely why we have encapsulation in OO.)
How this applies to color is left as an exercise to the student.