哪种设计模式适合——策略有意义?
我有一个简单的数据库表,用于存储通过电子邮件订阅文件夹或显示在网站上(仅在 Web UI 上)的用户列表。在存储表中,这是由数字控制的(1 - 在站点上显示 2 - 通过电子邮件)。当我在用户界面中显示时,我需要在用户订阅的每个文件夹旁边显示一个复选框(电子邮件和现场)。
有一个单独的表存储一组默认订阅,如果用户未表达其订阅,则这些默认订阅将适用于每个用户。这基本上是一个文件夹 ID 和一个虚拟组名称。
但是,电子邮件订阅不会计入应用这些默认组。因此,如果没有“现场”订阅,则应用默认组。这就是规则。
这里的策略模式怎么样(伪代码)
Interface ISubscription
public ArrayList GetSubscriptionData(Pass query object)
Public class SubscriptionWithDefaultGroup
Implement ArrayList GetSubscriptionData(Pass query object)
Public class SubscriptionWithoutDefaultGroup
Implement ArrayList GetSubscriptionData(Pass query object)
Public class SubscriptionOnlyDefaultGroup
Implement ArrayList GetSubscriptionData(Pass query object)
这是否有意义?我非常高兴收到任何批评/帮助/注释。我在学习。
干杯
I have a simple database table that stores list of users who have subscribed to folders either by email OR to show up on the site (only on the web UI). In the storage table this is controlled by a number(1 - show on site 2- by email). When I am showing in UI I need to show a checkbox next to each of folders for which the user has subscribed (both email & on site).
There is a separate table which stores a set of default subscriptions which would apply to each user if user has not expressed his subscription. This is basically a folder ID and a virtual group name.
But, Email subscriptions do not count for applying these default groups. So if no "on site" subscription apply default group. Thats the rule.
How about a strategy pattern here (Pseudo code)
Interface ISubscription
public ArrayList GetSubscriptionData(Pass query object)
Public class SubscriptionWithDefaultGroup
Implement ArrayList GetSubscriptionData(Pass query object)
Public class SubscriptionWithoutDefaultGroup
Implement ArrayList GetSubscriptionData(Pass query object)
Public class SubscriptionOnlyDefaultGroup
Implement ArrayList GetSubscriptionData(Pass query object)
does this even make sense? I would be more than glad for receive any criticism / help / notes. I am learning.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面怎么样呢。我的选择是使用装饰器模式。顺便说一句,我理解你的问题,总是有默认订阅,用户可以额外订阅更多内容。 装饰器用于这种增强,而策略用于替代实现。
策略允许您用替代实现来替换某些内容。装饰器透明地增强对象。
How about below. My choice is to use Decorator pattern. By the way I understood your problem, there are always default subscriptions and users can ADDITIONALLY subscribe for more. And Decorator is meant for this kind of ENHANCEMENTS while Strategy is for ALTERNATE IMPLEMENTATIONS.
Strategy allows you to replace something with an alternative implementation. Decorator transparently enhances objects.