两个对象重叠的模式
我确信这个问题已经被问过并得到回答,所以我提前为此道歉,但我没有找到要搜索的正确关键字。 搜索“Pattern”会遇到太多问题和问题。 A 是有用的。
我正在开发一个回归测试应用程序。 我在屏幕上显示一个表单,根据登录应用程序的用户,某些字段应该是只读的。 因此,我可以抽象一个字段对象,也可以抽象一个用户对象,但是我应该考虑什么模式来描述这两个概念的交集? 换句话说,我应该如何描述字段 1 和用户 A,该字段应该是只读的? 看起来只读(或不是)应该是 Field 类的属性,但正如我所说,这取决于哪个用户正在查看表单。 我考虑过一个简单的二维数组(例如 ReadOnly[Field,User] = True),但我想确保我选择了最有效的结构来表示它。
有没有关于这种数据结构的软件设计模式? 我是否让事情变得过于复杂了——二维数组是最好的方法吗? 正如我所说,如果有人提出并回答了这个问题,我深表歉意。 我在这里搜索过,没有找到任何东西,谷歌搜索也没有找到任何东西。
I'm sure this has already been asked and answered so I apologize in advance for that but I'm not figuring out the correct keywords to search for. Searching for "Pattern" hits way too many Q & A's to be useful.
I'm working on a regression testing app. I'm displaying a form on the screen and according to which user is logged in to the app some of the fields should be read-only. So I can abstract a field object and I can abstract a user object but what pattern should I be looking at to describe the intersection of these two concepts? In other words how should I describe that for Field 1 and User A, the field should be read-only? It seems like read-only (or not) should be a property of the Field class but as I said, it depends on which user is looking at the form. I've considered a simple two-dimensional array (e. g. ReadOnly[Field,User] = True) but I want to make sure I've picked the most effective structure to represent this.
Are there any software design patterns regarding this kind of data structure? Am I overcomplicating things--would a two-dimensional array be the best way to go here? As I said if this has been asked and answered, I do apologize. I did search here and didn't find anything and a Google search failed to turn up anything either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表驱动设计可能是有效的。
Steve Maguire 在Writing Solid Code 中提供了一些很好的例子。
它们也是捕获测试的好方法,请参阅 fit 。
在您的情况下,类似于:
顺便说一句,您可能想要对用户和用户类/角色/组进行建模,而不是将它们组合起来。
用户通常捕获谁(身份验证),而组/角色捕获什么(权限、能力)
Table driven designs can be effective.
Steve Maguire had few nice examples in Writing Solid Code .
They are also a great way to capture tests, see fit .
In your case something like:
As an aside you probably want to model both users and user classes/roles/groups instead of combining them.
A user typically captures who (authentication) while groups/roles capture what (permissions, capabilities)
乍一看,这听起来更像是您有两种不同类型的用户,并且他们具有不同的访问级别。 这可以通过继承(PowerUser、User)或通过包含为用户设置级别的安全对象或令牌来解决。
如果您不喜欢继承作为规则,您可以在应用程序上使用状态模式,装饰用户对象(Shudder)或者可能为不同的安全级别添加策略模式。 但我认为现在还为时过早,我通常不会应用模式,直到我对项目将如何增长和维护有明确的想法。
At first blush it sounds more like you have two different types of users and they have different access levels. This could be solved by inheritance (PowerUser, User) or by containing a security object or token that sets the level for the user.
If you don't like inheritance as a rule, you could use a State pattern on the application, Decorate the user objects (Shudder) or possibly add strategy patterns for differing security levels. But I think it's a little early yet, I don't normally apply patterns until I have a firm idea of how the item will grown and be maintained.