I am having trouble reconciling the Single Responsibility Principle with encapsulation. It seems like splitting responsibilities amongst classes requires exposing a lot of data. As an example, consider some object called DataPoints
. DataPoints
is filled with x and y coordinates, among other things. I can create a Generator class that fills DataPoints
. Now, let's say I want to plot those data points. Clearly, that's a separate responsibility that might come from a class called DataPointsPlotter
. But to plot the data, I need to know what the internal x and y coordinates are. With a single class handling both, that's no problem. x and y are internal variables, but both a create() and a print() method have access to those. I can expose x and y (perhaps through getters/setters--ugh) or I can pass the DataPoints
structure to the Plotter class, but it still needs to get inside to get x and y. I can have an instance of Plotter declared in the DataPoints
class to which I send x and y. But that's still an exposure.
How can I in this example plot x and y using the plotter without violating encapsulation?