Scenario: I stored some information (e.g. an array of doubles) in a class field (say field Measurements
, array of integers in a class MeasureData
). Now I would like to use this data to perform some calculations (e.g compute the arithmetic mean of the array, the maximum and the minimum). At the moment, I don't know if in the future I'll need to do any other operation on those data (e.g. maybe I will need to get the standard deviation, the sum or whatever). I'll have many objects of type MeasureData
.
Solution: I could write a class Calculator
, declare it final, use a private constructor and use several static methods to perform the calculations I need. This seems to make sense, since Calculator
acts as an utility class, without any field, much like the standard Math
class.
Problem: if, in a couple of months, I'll need to do any other calculation, I'll be needing to write another static method in Calculator
. Does this mean to violate the open/closed principle (after all, I'm modifying the implementation of the class Calculator
)?