is this a design pattern?
Posted
by Michel
on Stack Overflow
See other posts from Stack Overflow
or by Michel
Published on 2010-04-17T19:43:31Z
Indexed on
2010/04/17
20:33 UTC
Read the original article
Hit count: 232
Hi all,
i have to build some financial data report, and for making the calculation, there are a lot of 'if then' situations: if it's a large client, subtract 10%, if it's postal code equals '10101', add 10%, if the day is on a saturday, make a difficult calculation etc.
so i once read about this kind of example, and what they did was (hope i remember well) create a class with some base info and make it possible to add all kinds of calculationobjects to it.
So to put what i remembered in pseudo code
Basecalc bc = new baseCalc();
//put the info in the bc so other objects can do their if
bc.Add(new Largecustomercalc());
bc.Add(new PostalcodeCalc());
bc.add(new WeekdayCalc());
the the bc would run the Calc() methods of all of the added Calc objects. As i type this i think all the Calc objects must be able to see the Basecalc properties to correctly perform their calculation logic.
So all the if's are in the different Calc objects and not ALL in the Basecalc.
does this make sense?
I was wondering if this is some kind of design pattern?
© Stack Overflow or respective owner