Shakti
Shakti

Reputation: 2033

Java design pattern for analytics calculation

I have to calculate around 300 different analytics for example 1. Calculate mean of a given set 2. Calculate median of a given set Etc These calculators will be used in a batch process to calculate analytics from a set of data. I am planning to create an AbstractCalculator that will have all the common logic and then core implementation will be available in each of the child class's calculate method. I want to know is there a better way or is there an existing design pattern that I can refer to for such requirement. Only problem that I çan see is it will be difficult to manage 300 child classes.Is there a better way to handle such requirement Thanks Shakti

Upvotes: 2

Views: 1700

Answers (1)

Coder55
Coder55

Reputation: 559

You are searching for the strategy design pattern (https://en.wikipedia.org/wiki/Strategy_pattern)

Strategy lets the algorithm vary independently from clients that use it.[1] Strategy is one of the patterns included in the influential book Design Patterns by Gamma et al. that popularized the concept of using patterns in software design.

The strategy pattern specifies that you have a superclass, in your case for example AbstractCalculator with a method calculate(Setinput)

Each function you want to add to your programm can be added via declaring a new class which inherits from AbstractCalculator; The function(e.g. calculation of the mean of a given Set) is implemented in the calculate method of the subclass.

In fact, you would have to implement 300 different classes with this pattern - I suggest you to declare your functions in a library, which implements all functions with many classes less.

Upvotes: 2

Related Questions