I need to get an idea for a design pattern to use in my context. I have a simple concept as follows:
There are 12 months in the year and every month has a different amount of days in it. Every month I have a bunch of different stock groups that need to have calculations done on them. Lets assume I have an array of different stock item groups. I now need to calculate the area used for all stock groups over the year.
So to simplify:
Each stock group has a method 'calculateArea' which will return a value. This calculation needs to be run every month to get an updated area for the stock group.
My idea was to use the iterator pattern to simply loop over each month and inside that iterate each stock group and run the calculate method for all. The implementation there would pretty much just boil down to 2 nested for loops. I know it's not the right OO approach just by looking at the above sentence.
What was suggested to me was the visitor pattern. This is something I have not used before so I'm trying to put it into context here.
I see this as setting up the 12 months as separate objects and then I would iterate over each month and each period would visit each stock group and do the calculations??? This is where it goes pear-shaped in my thinking.
The reason for the visitor pattern usage would also be that at some future point we would be calculating something completely different over the same month increments and would like to simply extend the existing framework/architecture.
To clarify, I have time for implementation so I'm trying to spend time up front to give it the best up-front design.
Any ideas/suggestions appreciated.
Aucun commentaire:
Enregistrer un commentaire