so I've been using a strategy pattern together with the template method pattern to create some logic that changes over the years. Let me try to explain:
- My logic is different per Country (EN, PT)
- For each country it's also diff per year but some methods can be the same over the years.
So what I've got in terms of code is:
- common interface "IWork"
- a strategy class that giving the country and year returns the correct country-year class. ex: Work_EN_2018 or Work_PT_2019
- country-year implementations (ex: Work_EN_2018) that extends from a base class (BaseWork_EN)
- base class per country (BaseWork_EN or BaseWork_PT)
It all works good but now with over 10 years things are starting to be hard to maintain all because some methods are the same for multiple years but after a specific year logic changes. So our solution for now is if logic changes for a specific method we change the base class method with the new logic and for all previous years we override the method in the year class (ex: Work_EN_2017, Work_EN_2018, etc). This is very troublesome and hard to maintain so my question is how can this old logic be maintained in a better way?
For now, I'm thinking in creating an utils class with these old methods so that at least in older class years I just reference one single implementation, it's this the only solution?
Sorry if the description of the problem is not clear.
Thanks
Aucun commentaire:
Enregistrer un commentaire