两个对象重叠的图案 [英] Patterns for the overlap of two objects

查看:145
本文介绍了两个对象重叠的图案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信这已经被问及回答了,所以我提前道歉,但我没有找出正确的关键字搜索。搜索模式的打法太多Q& A有用。



我正在研究一个回归测试应用程序。我在屏幕上显示一个表单,根据哪个用户登录到应用程序,一些字段应该是只读的。所以我可以抽象一个字段对象,我可以抽象一个用户对象,但是我应该看什么模式来描述这两个概念的交集?换句话说,我应该如何描述Field 1和User A,该字段应该是只读的?似乎只读(或不)应该是Field类的属性,但正如我所说,这取决于哪个用户正在查看该表单。我已经考虑过一个简单的二维数组(例如ReadOnly [Field,User] = True),但是我想确保我选择了最有效的结构来代表这个数组。



有关这种数据结构的任何软件设计模式?我是否过于复杂的事情 - 二维数组是否是去这里的最佳方法?正如我所说,如果这被问及回答,我道歉。我在这里搜索,没有找到任何东西,Google搜索也没有找到任何东西。

解决方案

表驱动设计可以有效。
史蒂夫·马奎尔(Steve Maguire)在 >它们也是捕获测试的好方法,请参阅适合



在你的情况下,如下所示:

  Field1ReadonlyRules = {
'user class 1':True ,
'user class 2':False
}

field1.readOnly = Field1ReadonlyRules [someUser.userClass]

除此之外,您可能希望模拟用户和用户类/角色/组,而不是组合它们。
用户通常会捕获
(认证),而组/角色捕获 (权限,功能)


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.

解决方案

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:

Field1ReadonlyRules = {
    'user class 1' : True,
    'user class 2' : False
}

field1.readOnly = Field1ReadonlyRules[ someUser.userClass ]

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)

这篇关于两个对象重叠的图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆