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

Represents a single group. A group has a name and zero or more users. Users are tracked by name. More...

Collaboration diagram for Group:
Collaboration graph

Public Member Functions

bool ContainsUser (string name)
 Determine if the specified user is in this group. This is a case- sensitive search.
 
void AddUser (string name)
 Add the specified user to this group. If the user is already in the group, the operation is ignored.
 
void RemoveUser (string name)
 Remove a user from this group. If the user is not in the group then the operation is ignored.
 
override bool Equals (object? obj)
 Override to compare a Group or string to this Group.
 
override int GetHashCode ()
 Generate a hash code for this instance.
 

Package Functions

 Group (string name)
 Constructor.
 

Properties

string Name [get]
 The name of the group (read-only).
 
string[] Users [get]
 The names of users in this group (read-only).
 

Private Attributes

List< string > _users = new List<string>()
 The list of users in this group.
 

Detailed Description

Represents a single group. A group has a name and zero or more users. Users are tracked by name.

Definition at line 26 of file Mediator_Group_Classes.cs.

Constructor & Destructor Documentation

◆ Group()

Group ( string  name)
inlinepackage

Constructor.

Parameters
nameName of the group to use.

Definition at line 37 of file Mediator_Group_Classes.cs.

References Group.Name.

Member Function Documentation

◆ AddUser()

void AddUser ( string  name)
inline

Add the specified user to this group. If the user is already in the group, the operation is ignored.

Parameters
nameName of the user to add. Cannot be null or empty.
Exceptions
ArgumentNullExceptionThe 'name' parameter must specify a user name.

Definition at line 75 of file Mediator_Group_Classes.cs.

References Group._users, and Group.ContainsUser().

Referenced by UserGroupMediator.AddUserToGroup().

◆ ContainsUser()

bool ContainsUser ( string  name)
inline

Determine if the specified user is in this group. This is a case- sensitive search.

Parameters
nameName of the user to look for.
Returns
Return true if the user is in this group; otherwise false.

Definition at line 64 of file Mediator_Group_Classes.cs.

References Group._users.

Referenced by Group.AddUser(), UserGroupMediator.GetGroupsWithUser(), UserGroupMediator.IsUserInGroup(), Group.RemoveUser(), and UserGroupMediator.RemoveUserFromAllGroups().

◆ Equals()

override bool Equals ( object?  obj)
inline

Override to compare a Group or string to this Group.

Parameters
objA string or an instance of the Group class.
Returns
True if the names are equal (case-sensitive).

Definition at line 107 of file Mediator_Group_Classes.cs.

References Group.Name.

◆ GetHashCode()

override int GetHashCode ( )
inline

Generate a hash code for this instance.

Because we overrode Equals(), we need to override GetHashCode().

Returns
Hash code of the name, since that is what uniquely identifies a Group instance.

Definition at line 130 of file Mediator_Group_Classes.cs.

References Group.Name.

◆ RemoveUser()

void RemoveUser ( string  name)
inline

Remove a user from this group. If the user is not in the group then the operation is ignored.

Parameters
nameThe name of the user to remove.

Definition at line 94 of file Mediator_Group_Classes.cs.

References Group._users.

Referenced by UserGroupMediator.RemoveUserFromAllGroups(), and UserGroupMediator.RemoveUserFromGroup().

Member Data Documentation

◆ _users

List<string> _users = new List<string>()
private

Property Documentation

◆ Name

string Name
get

◆ Users

string [] Users
get

The names of users in this group (read-only).

Definition at line 50 of file Mediator_Group_Classes.cs.

Referenced by UserGroupMediator.GetUsersInGroup().


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