ArticleslgStudy

computer science

Role Class Model

Role Class Model is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Role Class Model rather than just read about it. In short: In computer science, the role class model is a role analysis pattern described (but not invented ) by Francis G. Mossé in his article on Modelling Roles.

Role Class Model — main illustration
Role Class Model — illustration

Key takeaways

  • Role Class Model belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Role Class Model to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Role Class Model from memory before moving on to harder problems.

Reference excerpt

In computer science, the role class model is a role analysis pattern described (but not invented ) by Francis G. Mossé in his article on Modelling Roles. The role class pattern provides the ability for a class to play multiple roles and to embed the role characteristic in a dedicated class. In our society, as we built it, roles are everywhere. Anyone trying to work in a team to create something has a role. In cinematography, many different persons take part in the creation of a film: the film director, the producer, actors, play writer(s), etc. Even our State organisations are based on various roles. In a Republic, you have a President, Ministers, Deputies, etc. Dealing with these situations is one of the problems encountered most during object-oriented analysis. Francis G. Mossé has identified 5 role analysis patterns that can be used to solve most role related problems: Role Inheritance, Association Roles, Role Classes, Generalised Role Classes and Association Class Roles. They all have various degrees of constraints, flexibility or power, which together offer a complete solution to most role-related problems.

Intent A model that allows a class to play one or more roles at the same time. A role - as defined by Francis Mossé in Modelling Roles - is a concept of a purpose that a class could have in a certain context.

Context The following example is given: Many persons work on a film, each of them with a different role. At the difference of other concepts, a person is not restricted to one role. One could be both the director and a character in a film. Modelling roles for such a concept would require that a class could play more than a single role. A solution using inheritance to conceptualise a role - cf. the Inheritance Role Model - is not possible, as this would allow a person to play only a single role. As one can see in Figure 1 below, the inheritance role model says that a character, who is a person, is playing in a film. But there is no way to say that the person playing the character is also the director. Because, the inheritance makes a character a person in general, not a particular person.

Problem As explained in Context, using inheritance to play more than one role cannot be considered, because a class could not play two roles at the same time in such a context (cf. the Inheritance Role Model). The expectation is to have a model where a class could be seen as more than one concept or role, and where attributes specific to one of those concepts can be specified.

Solution A solution to the previous problem could be to use the Association Role Model, which could create an association between a person and a film. However, specific information on each role could not be stored in such a case. The role class model provides the flexibility of the association with role-specific attributes and even class operations, if needed.

This meta model - in Figure 2 - shows the role class like an element linking the Client and the BaseClass. For the Client interacting with the Role is like interacting with the Base Class itself, but from the perspective, it is expecting. The advantage having the role as a class is that attributes can be bound to it. Another situation where the Role pattern is interesting is when you've the following situation:

Then you realise that as a contract holder, the Person has specific attributes. The holder UML role becomes a dedicated class ContractHolder with these specific attributes. Note that in that case that the multiplicity near Person and Contract are always 1. It means that you've one ContractHolder object for each association between a Contract and a Person.

Real-world example

Cinema

A simple application of the role class model in a real example is in the 7th art (see Figure 3), the cinematography. This art involves a creation (the Film) and people to create it. Each person has a different role in the film, they could be actors and play characters, they could be director or scenarist, etc. A person is not limited to one role in a film, they can be both actors and directors and even more. For example, the film Scoop (2006) has been directed by Woody Allen, he is also the scenarist and he plays the role of Sid Waterman.

In Figure 4, one can see in more detail the role that each person can play in a film. From the film, it is possible to ask the list of crews and cast that help elaborated it. Each person has one or more roles (e.g. actor, director, producer, cameraman, etc.) in the film and can participate in more than one film. A person could even be an actor in a film and a producer in another. One advantage of using a role class in the case of the actor role is that the character qualities can be stored within the role. This is true for the actor role, this is also true for other roles, however maybe not all. Only a few of the possible role have been modelled in Figure 4. One remark easily visible is that not all the role needs attributes and using the role class model for all of them is unnecessary (like for the Director role). In addition, there is a lot of redundancy between each role class. Redundancy in computer science means more work in maintenance, which is not wished.

Strengths and weaknesses The employment of this model depends on the business process. The analysis pattern "Role Class Model" offers a possibility to employ a model with linking between a base class and the client. In addition inheritance is not a part of the solution because of the flexibility of zero or multiple roles (role-specific attributes and operations). Strength implies also its counterpart's weakness. The problem of the role class model is the redundancy, for example the method getName is visible in all of the role classes described in Figure 4. If this is considered inconvenient, the role class generalisation model as defined in Modelling Roles is a possible way to go.

See also Francis G. Mossé has described other solutions to the role problem.

Role Inheritance Association Roles Generalized Role Classes Association Class Roles Association Class Roles with role type, which is a refinement of the previous. Referential transparency

References

… excerpt ends here. Continue reading the full article.

Illustrations

Role Class Model: Figure 2: Role class meta model (using UML meta model representation)
Figure 2: Role class meta model (using UML meta model representation)
Role Class Model: Figure 2.1: Contract holder without role pattern
Figure 2.1: Contract holder without role pattern
Role Class Model: Figure 2.2: Contract holder with role pattern
Figure 2.2: Contract holder with role pattern
Role Class Model: Figure 3: Application of the role class model to the 7th Art (overview)
Figure 3: Application of the role class model to the 7th Art (overview)
Role Class Model: Figure 4: The 7th Art in more details (using UML class diagram representation). Click to enlarge.
Figure 4: The 7th Art in more details (using UML class diagram representation). Click to enlarge.

Worked examples

Example 1 — a first encounter with Role Class Model

Start with the simplest possible case. Write down what Role Class Model claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Role Class Model before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Role Class Model ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Role Class Model

In research
Role Class Model appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Role Class Model in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Role Class Model is common in secondary-school and first-year university syllabi. It links to neighbouring topics Software analysis patterns, Unified Modeling Language, so understanding it makes those chapters shorter.
In everyday life
Look for Role Class Model outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Role Class Model in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Role Class Model means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Role Class Model out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Role Class Model in simple terms?

In computer science, the role class model is a role analysis pattern described (but not invented ) by Francis G. Mossé in his article on Modelling Roles.

Why does Role Class Model matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Role Class Model?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Role Class Model.

Tags

  • Software analysis patterns
  • Unified Modeling Language

Keep exploring