Templates for overlapping two objects

I am sure that this has already been asked and answered, so I apologize in advance for this, but I will not find out the correct keywords for the search. A search for "Pattern" means that too many Q and A will be useful.

I am working on a regression testing application. I show the form on the screen and according to which the user enters the application, some fields should be read-only. Therefore, I can abstract the field object, and I can abstract the user object, but what pattern should I look for to describe the intersection of these two concepts? In other words, how should I describe this for field 1 and user A, should the field be read-only? It seems that read-only (or not) should be a property of the Field class, but, as I said, depends on which user is looking at the form. I looked at a simple two-dimensional array (for example, ReadOnly [Field, User] = True), but I want to make sure that I have chosen the most efficient structure to represent this.

Are there any software design patterns regarding this data structure? I am confusing something - could a two-dimensional array be the best here? As I said, if asked and answered about this, I apologize. I did a search here and did not find anything, and a Google search could not do anything.

+3
source share
2 answers

Table driven projects can be effective. Steve Maguire had some good examples of 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 ]

, , , // . , (), / , (, )

+2

, . (PowerUser, User) , .

, , , (Shudder) , , . , , , , .

+1

Source: https://habr.com/ru/post/1696760/


All Articles