How can you create flexible enums with different behaviors and associated values?

Enums are great to group objects with similar behavior. They are also efficient because only one instance of them will get created. However, it’s hard to implement enums for classes that has slightly different behaviors. Let me illustrate with an example.

Example: Stats Calculator

Let’s say we want write a Stats Calculator to compute mathematical statistics for list of values for eg. SUM, COUNT, AVG, QUANTILES . Let’s first define an interface.


Read on Medium

comments powered by Disqus

Facebook Comments