开发者

how to pick the most suitable design pattern

I have a problem which is as follows.

We are starting to accept corporate cards in our Kiosks, The corporate cards authorization algorithm/routines will be different for companies. We would like to have a design in place which will help us to add a new algorithm/routines to the existing system with minimum coding whenever a company approaches us with their algorithm/routines.

Thanks in ad开发者_JAVA百科vance,

Joe.


Take a look at the Strategy design pattern

Guess this would be the closest to what you are trying to achieve!

You will need a CardStrategyBase class with standard methods to handle the work. Then, Card1Strategy class, Card2Strategy class,... etc. Will have the actual algorithm implementation specific to each card type. All stuff common to all card types can go into the CardStrategyBase class.


As other folks said, Strategy Pattern suits this scenario very well.

When your entities (Companies) differ in behavior(Authorization), encapsulate the behavior and make it separate from the entities' definition.


You may use Strategy Pattern http://sourcemaking.com/design_patterns/strategy this is good reference for your work


Dependency Inversion (DI).

The "problem" with the strategy pattern is that it while it let's you pick from a list of available implementations it doesn't address adding new implementations for new cards.

Generally speaking, most decent DI implementations allow you to drop new implementations in without having to do a major deployment; after which it might only be a matter of adding appropriate configuration to enable the new implementation(s).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜