Design Pattern Examples
Overview of object-oriented design patterns
UserGroupMediator Class Reference

Represents the mediator between caller, users, and groups. All users and groups are identified by string name. The names are case-sensitive. More...

Collaboration diagram for UserGroupMediator:
Collaboration graph

Public Member Functions

void AddUser (string name)
 Add a user to the list of known users. If the name is already in the list of users, the request to add is ignored.
 
void RemoveUser (string name)
 Removes the specified user from the list of known users, if the user exists. Also removes the user from all groups.
 
void AddGroup (string name)
 Add a group to the list of known groups. If the group is already in the list, the request to add is ignored.
 
void RemoveGroup (string name)
 Remove the specified group from the list of known groups if the group exists.
 
void AddUserToGroup (string userName, string groupName)
 Add the specified user to the specified group. If the user is already in the group, do nothing. The user must exist.
 
void RemoveUserFromGroup (string userName, string groupName)
 Remove the specified user from the specified group.
 
void RemoveUserFromAllGroups (string userName)
 Remove the specified user from all existing groups.
 
bool IsUserInGroup (string userName, string groupName)
 Determine if the specified user is in the specified group.
 
string[] GetGroupsWithUser (string userName)
 Retrieve a list of all groups that contain the specified user.
 
string[] GetUsersInGroup (string groupName)
 Retrieve a list of users in the specified group.
 
string[] GetAllGroups ()
 Retrieve a list of all known groups.
 
string[] GetAllUsers ()
 Retrieve a list of all known users.
 

Private Attributes

UserGroupsContainer _userGroupsContainer = new UserGroupsContainer()
 

Detailed Description

Represents the mediator between caller, users, and groups. All users and groups are identified by string name. The names are case-sensitive.

Definition at line 35 of file Mediator_Class.cs.

Member Function Documentation

◆ AddGroup()

void AddGroup ( string  name)
inline

Add a group to the list of known groups. If the group is already in the list, the request to add is ignored.

Exceptions
ArgumentNullExceptionThe 'name' parameter cannot be null or empty.
Parameters
nameName of the user to add. Must not be null or empty.

Definition at line 72 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, GroupList.AddGroup(), and UserGroupsContainer.Groups.

Referenced by Mediator_Exercise.Mediator_SetupGroups().

◆ AddUser()

void AddUser ( string  name)
inline

Add a user to the list of known users. If the name is already in the list of users, the request to add is ignored.

Parameters
nameName of the user to add. Must not be null or empty.
Exceptions
ArgumentNullExceptionThe 'name' parameter cannot be null or empty.

Definition at line 48 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, UserList.AddUser(), and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Mediator_SetupUsers().

◆ AddUserToGroup()

void AddUserToGroup ( string  userName,
string  groupName 
)
inline

Add the specified user to the specified group. If the user is already in the group, do nothing. The user must exist.

Parameters
userNameName of user to add. Must be an existing user.
groupNameName of group to add user to. Must be an existing group.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 96 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, Group.AddUser(), GroupList.FindGroup(), UserList.FindUser(), UserGroupsContainer.Groups, and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Mediator_SetupGroups(), and Mediator_Exercise.Run().

◆ GetAllGroups()

string[] GetAllGroups ( )
inline

Retrieve a list of all known groups.

Returns
An array of group names.

Definition at line 265 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, GroupList.GroupNames, and UserGroupsContainer.Groups.

Referenced by Mediator_Exercise.Run().

◆ GetAllUsers()

string[] GetAllUsers ( )
inline

Retrieve a list of all known users.

Returns
An array of user names.

Definition at line 275 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, UserList.UserNames, and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Run().

◆ GetGroupsWithUser()

string[] GetGroupsWithUser ( string  userName)
inline

Retrieve a list of all groups that contain the specified user.

Parameters
userNameName of the user to look for. Must be an existing user.
Returns
An array of group names containing the user. Array is empty if the user is not found in any group.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 217 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, Group.ContainsUser(), GroupList.FindGroup(), UserList.FindUser(), GroupList.GroupNames, UserGroupsContainer.Groups, and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Run().

◆ GetUsersInGroup()

string[] GetUsersInGroup ( string  groupName)
inline

Retrieve a list of users in the specified group.

Parameters
groupNameName of the group to examine. Must be an existing group.
Returns
Returns an array of user names. The array can be empty if no users are in the group.
Exceptions
ArgumentExceptionGroup does not exist.

Definition at line 249 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, GroupList.FindGroup(), UserGroupsContainer.Groups, and Group.Users.

Referenced by Mediator_Exercise.Run().

◆ IsUserInGroup()

bool IsUserInGroup ( string  userName,
string  groupName 
)
inline

Determine if the specified user is in the specified group.

Parameters
userNameName of user to find. Must be an existing user.
groupNameName of group to look in. Must be an existing group.
Returns
Returns true if the user is in the group; otherwise, returns false.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 186 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, Group.ContainsUser(), GroupList.FindGroup(), UserList.FindUser(), UserGroupsContainer.Groups, and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Run().

◆ RemoveGroup()

void RemoveGroup ( string  name)
inline

Remove the specified group from the list of known groups if the group exists.

Parameters
nameName of group to remove.

Definition at line 83 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, UserGroupsContainer.Groups, and GroupList.RemoveGroup().

◆ RemoveUser()

void RemoveUser ( string  name)
inline

Removes the specified user from the list of known users, if the user exists. Also removes the user from all groups.

Parameters
nameName of user to remove.

Definition at line 59 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, UserList.RemoveUser(), UserGroupMediator.RemoveUserFromAllGroups(), and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Run().

◆ RemoveUserFromAllGroups()

void RemoveUserFromAllGroups ( string  userName)
inline

Remove the specified user from all existing groups.

Parameters
userNameName of user to remove. Must be an existing user.
Exceptions
ArgumentExceptionUser does not exist.

Definition at line 153 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, Group.ContainsUser(), GroupList.FindGroup(), UserList.FindUser(), GroupList.GroupNames, UserGroupsContainer.Groups, Group.RemoveUser(), and UserGroupsContainer.Users.

Referenced by UserGroupMediator.RemoveUser(), and Mediator_Exercise.Run().

◆ RemoveUserFromGroup()

void RemoveUserFromGroup ( string  userName,
string  groupName 
)
inline

Remove the specified user from the specified group.

Parameters
userNameName of user to remove. Must be an existing user.
groupNameName of group to remove user from. Must be an existing group.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 125 of file Mediator_Class.cs.

References UserGroupMediator._userGroupsContainer, GroupList.FindGroup(), UserList.FindUser(), UserGroupsContainer.Groups, Group.RemoveUser(), and UserGroupsContainer.Users.

Referenced by Mediator_Exercise.Run().

Member Data Documentation

◆ _userGroupsContainer


The documentation for this class was generated from the following file: