我应该使用什么设计模式?使用Spring框架

发布于 2024-10-10 00:34:53 字数 405 浏览 2 评论 0原文

我们正在创建拍卖网站。拍卖有不同类型。并根据拍卖类型,宣布获胜者。

例如:- *在一种类型的拍卖中:-出价较高的用户获胜。 *在其他类型中:- 出价最低的用户获胜。 *在某些类型中:- 所有者决定获胜者。 *在某些类型中:- 前 10 名投标人赢得拍卖。

看来策略模式非常适合设计决定“拍卖获胜者”的模块。

因此

,系统将根据“拍卖类型”选择适当的算法来决定获胜者。将提供拍卖类型选择获胜者所需的所有参数。 我正在考虑使用策略模式(可能是AOP方式)来实现winnerDeclare模块。

该应用程序基于 SpringFramework ,任何人都可以建议我一个优雅的设计来处理上述问题。 我应该使用哪种模式?我应该选择 AOP 吗?

如果需要,我可以提供更多详细信息。

先感谢您。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

琉璃繁缕 2024-10-17 00:34:53

这是一个广泛的问题,我的答案是尝试并专注于使用简单的面向对象结构正确建模问题,而不是“哪种模式适合这里”。模式很可能会出现,您不需要立即命名它们。

另外,如果您是 Spring 新手,我建议您忘记 AOP。它现在对你没有帮助。而且,为了使用 AOP 而使用 AOP 也没有什么帮助。

ps 策略在这里看起来不错。

This is a broad question and my answer is to try and stay focused on correctly modeling the problem using simple object oriented structures and less on "which pattern fits here". Pattern(s) will most probably emerge and you don't need to name them straight away.

Also I suggest forgetting about AOP in case you are new to Spring. It will not help you right now. Also, using AOP for the sake of using it will not help as well.

p.s Strategy seems good here.

北城半夏 2024-10-17 00:34:53

这个问题实际上并没有任何 Spring 特有的东西。是的,策略模式可能是正确的选择。

创建一个服务接口来确定拍卖获胜者并创建它的一个或多个实现。在您的业务代码中,始终引用服务接口,而不是实现类,这样您就可以轻松切换实现(有或没有Spring)。 (阅读 Joshua Bloch 的 Effective Java 以更好地理解接口编程)

忘记 Spring AOP。它可以解决很多问题,但不能解决你的问题。您的问题是定义应用程序的核心模块并将它们连接在一起(通常使用 Spring 或另一个 DI 容器完成)

基本上,当您创建服务接口时,您需要决定“这个东西应该做什么?”当您实现接口时,您会决定“这个东西应该如何做?”

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?'

木有鱼丸 2024-10-17 00:34:53

您可以使用以下场景:

一个具有 Bean 列表的主 Bean。每个 bean 代表一个流(“最高出价”、“最低出价”等)。我们称它们为 flowBean。
每个flowBean应该有一个或多个choiseBean。
choiseBean根据拍卖的输入决定是否应该执行flowBean。

抱歉无法提供示例。

PS:除了我的建议,我同意cherouvim!

you could use the following scenario:

One main bean that has a list of beans. Each bean representing a flow ('highest bid', 'lowest bid', etc.). Lets call them flowBeans.
Each flowBean should have one or more choiseBeans.
The choiseBean decides whether the flowBean should execute or not, based on the input of the auction.

Sorry for not being able to provide an example..

PS: Besides my suggestion, I agree with cherouvim!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文