Teams and Roles
Why Roles?
The difference of a Role compared to a Mixin is the following. While a Mixin can be defined single standing, a role is always defined within a group with other roles, which is called team. Roles can therefore only get assigned to an object, if all roles of this team are assigned at the same time. The team itself can have attributes that are connected to all roles of the team, e.g. the company, an employee, and an employer are working at.
Contexts.Role
— TypeRole
Abstract supertype for all role types. Roles represent context-dependent behaviors or responsibilities.
Concrete roles should be defined within the @newTeam
and @newDynamicTeam
macro.
Contexts.Team
— TypeTeam
Abstract supertype for all team types. Teams group roles and their relationships in a relational context.
Concrete teams should be defined within the @newTeam
and @newDynamicTeam
macro.
Contexts.@newTeam
— Macro@newTeam(contextName, teamName, teamContent)
Macro to define a new Team type for a context, with specified roles and attributes. Creates a mutable struct subtype of Team and role structs, and registers them.
A Team always contains a fixed number of roles. Once a team is created, the role assignment cannot be changed without dissolving the team and creating a new one.
Arguments:
contextName
: The context for the teamteamName
: The name of the teamteamContent
: Block containing:
- @relationalAttributes: relational attributes of the team
- @role: role definitions
@role definitions must contain at least two roles. The syntax for defining roles is: @role RoleName << NaturalType [<: RoleSuperType] begin # role-specific attributes end
Example: @context Tournament @newTeam ChessGame begin @relationalAttributes begin place::String end @role BlackPlayer << Person <: Player begin end @role WhitePlayer << Person <: Player begin end end
@newTeam(teamName, teamContent)
Macro to define a new Team type without a context. Creates a mutable struct subtype of Team and role structs, and registers them.
A Team always contains a fixed number of roles. Once a team is created, the role assignment cannot be changed without dissolving the team and creating a new one.
Arguments:
teamName
: The name of the teamteamContent
: Block containing:
- @relationalAttributes: relational attributes of the team
- @role: role definitions
@role definitions must contain at least two roles. The syntax for defining roles is: @role RoleName << NaturalType [<: RoleSuperType] begin # role-specific attributes end
Example: @newTeam ChessGame begin @relationalAttributes begin place::String end @role BlackPlayer << Person <: Player begin end @role WhitePlayer << Person <: Player begin end end
Contexts.assignRoles
— MethodassignRoles(context::Union{Context, Nothing}, team::Team, roles...)
Assigns roles to objects in a team within a context.
Arguments:
context
: Context or nothingteam
: Teamroles...
: Pairs of (object, Role)
Example: assignRoles(ctx, team, obj1 => RoleA, obj2 => RoleB)
Contexts.disassignRoles
— MethoddisassignRoles(context::Union{Context, Nothing}, t::Team, roles::Pair...)
Removes role assignments from objects in a team within a context.
Arguments:
context
: Context or nothingt
: Teamroles...
: Pairs of (Role, object)
Example: disassignRoles(ctx, team, RoleA => obj1, RoleB => obj2)
Contexts.getRoles
— MethodgetRoles(context::Union{Context, Nothing}, obj, role::Type, teamType::Type)
Returns all roles of a given type in a team of a given type for an object in a context.
Arguments:
context
: Context or nothingobj
: Objectrole
: Role typeteamType
: Team type
Example: getRoles(MyContext, obj, Manager, ProjectTeam)
Contexts.getRole
— MethodgetRole(context::Union{Context, Nothing}, obj::T, team::DynamicTeam) where T
Returns the role for an object in a dynamic team in a context.
Arguments:
context
: Context or nothingobj
: Objectteam
: DynamicTeam type
Example: getRole(MyContext, obj, MyDynTeam)
Contexts.getRolesOfTeam
— MethodgetRolesOfTeam(context::Union{Context, Nothing}, team::Team)
Returns all roles in a team in a context.
Arguments:
context
: Context or nothingteam
: Team type
Example: getRolesOfTeam(MyContext, MyTeam)
Contexts.getTeam
— FunctiongetTeam(context::Union{Context, Nothing}, teamType::Type, rolePairs...)
Returns the first team in a context that matches the given role pairs.
Arguments:
context
: Context or nothingteamType
: Team typerolePairs
: Vararg of role type and object type pairs
Example: getTeam(MyContext, MyTeam, RoleA=>Person, RoleB=>Manager)
Contexts.hasRole
— MethodhasRole(context::Union{Context, Nothing}, obj, role::Type, team::Team)
Checks if an object has a specific role in a specific team in a context.
Arguments:
context
: Context or nothingobj
: Objectrole
: Role typeteam
: Team type
Returns true or false.
Example: hasRole(MyContext, obj, Manager, MyTeam)
Contexts.getTeamPartners
— MethodgetTeamPartners(context::Union{Context, Nothing}, obj::Any, roleType::Type, team::Team)
Returns the partner object in a team for the specified object and role type in a context.
Arguments:
context
: Context or nothingobj
: Object to find partner forroleType
: Role typeteam
: Team type
Returns a partner group (Dict).
Example: getTeamPartners(ctx, alice, Manager, MyTeam)
Contexts.getObjectOfRole
— MethodgetObjectOfRole(context::Union{Context, Nothing}, team::Type, role::Type)
Returns all objects in a context that have a specific role in a specific team.
Arguments:
context
: Context or nothingteam
: Team typerole
: Role type
Example: getObjectOfRole(MyContext, MyTeam, Manager)
Contexts.getObjectOfRole
— MethodgetObjectOfRole(context::Union{Context, Nothing}, role::Role)
Returns the object in a context that has a specific role.
Arguments:
context
: Context or nothingrole
: Role type
Example: getObjectOfRole(MyContext, Manager)
Contexts.getObjectOfRole
— MethodgetObjectOfRole(role::Role)
Convenience function to getObjectOfRole with no context.
Arguments:
role
: Role type
Example: getObjectOfRole(Manager)
Teams and roles allow you to model collaborative structures in contexts. Use @newTeam
to define teams and their roles, and assignRoles
/disassignRoles
to manage role assignments. Query roles and teams with the provided functions.
See also: assignRoles
, getRoles