Hello,
I've been thinking for days how to solve the problem below, but I need some support of you guys.
I'm sure there exists some technique or a
pattern to solve easily my problem.
Before continuing,
you should know that for my case it's fobidden to modify the datamodel (otherwise my problem could have been solved by just inheritance and
polymorphism.
So, in our model there are several classes in which some properties exist that need to be used for applying a complicated algorithm.
We receive from our backend a unsorted list of objects of a certain class, and the result of that algorithm sorts the objects in a certain way and change some other properties of those classes.
The problem is, those classes are completely unrelated and the property names of those classes are completely different.
The algorithm that has to be applied is exactly the same.
As I don't want to duplicate the algorithm for handling each type of class, I'm looking for the right programming technique to apply.
Do you have any suggestions or hints please?
Thank you sooo much!
simplified Example of what I need to do -
imagine that the same algorithm
For the class User:
- sorts the elements of users, based upon an algorithm applied on the birthDate and marriageDate
- thereafter calculates the expected children, based upon an algorithm applied on the birthDate and marriageDate
For the class Company:
- sorts the elements of planets, based upon an algorithm applied on the startupDate and introductionToStockExchange
- thereafter calculates the expected revue, based upon an algorith applied on the startupDate and the introductionToStockExchange