I'm reading Clean Code
In Chapter 6, Objects and data structure
First talk about Data Abstraction:
Hiding implementation is not just a matter of putting a layer of functions between the variables. Hiding implementation is about abstractions! A class does not simply push its variables out through getters and setters. Rather it exposes abstract interfaces that allow its users to manipulate the essence of the data, without having to know its implementation.
We do not want to expose the details of our data. Rather we want to express our data in abstract terms.
And there is an example:
Concrete Point:
public class Point {
public double x;
public double y;
}
Abstract Point:
public interface Point {
double getX();
double getY();
void setCartesian(double x, double y);
double getR();
double getTheta();
void setPolar(double r, double theta);
}
And then continue with:
The beautiful thing about Abstract Poin is that there is no way you can tell whether the implementation is in rectangular or polar coordinates. It might be neither! And yet the interface still unmistakably represents a data structure.
But it represents more than just a data structure. The methods enforce an access policy. You can read the individual coordinates independently, but you must set the coordi- nates together as an atomic operation.
So I wonder how would it be a Rectangular Point class without violating 'I' in SOLID, Interface Segregation???
Does Rectangular Point Really need to implement getTheta
and setPolar
Functions???