We are creating auction website. There are different types of auction. and depending on type of auction, winner declaration is done.
eg:- *In one type of auction:-User who bids higher wins.
*In other type:- User with minimum bid wins.
*in some type:- owner decides winner.
*In some type:- First 10 bidder wins the auction.
It seems that Strategy Pattern is a good match for designing the module which will decide the “Auction Winner”.
So
Based on the “type of auction”, system will select the appropriate alogrithm to decide the winner.All parameters required by the auction type in order to choose winner will be provided.
I am thinking to use strategy pattern (may be in AOP way) to imlement winnerDeclare module.
The application is based on SpringFramework , could anybody suggest me a elegant design to handle problem mentioned above.
Which pattern should I use? Should I go for AOP ?
I can provide more details if required.
Thank you in advance.
There is not really anything Spring-specific to this question. Yes, the Strategy Pattern is probably the right choice.
Create a service interface to determine the auction winner and create one or more implementations of it. In your business code, always reference the service interface, not the implementation class, that way you can easily switch implementations (with or without Spring). (Read Joshua Bloch’s Effective Java to better understand programming with interfaces)
Forget Spring AOP. It solves many problems, but not yours. Your problem is to define the core modules of your application and to wire them together (which is usually done with Spring or another DI container)
Basically, when you create a service interface, you need to decide ‘What should this thing do?’ And when you implement the interface you decide ‘How should this thing do it?’