unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
119 stars 42 forks source link

Apply flyweight pattern to Calculator #330

Closed keilw closed 3 years ago

keilw commented 3 years ago

The Calculator class has static of() 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.

andi-huber commented 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.

keilw commented 3 years ago

Singleton may be the wrong term in this case but applying the pattern using of() instead of the contstructor should be encouraged.