Closed keilw closed 3 years ago
Calculator is not designed to be a singleton. Instead each calculation gets its own (throw away) calculator instance for thread safety.
However, no objections to hide the default (no arg) constructor and make the class final.
Singleton may be the wrong term in this case but applying the pattern using of()
instead of the contstructor should be encouraged.
The
Calculator
class has staticof()
method and private methods but it is not final and does not prevent calling the constructor either. It does not make sense there, so it should be made a true singleton.