Expand description

The Mediator design pattern example module

A mediator is instantiated then populated with users and groups. Users are added to some of the groups. The users handler and the groups handler are completely separate from each other; the mediator only makes it look like they are working on together.

A series of operations are then performed through the mediator. The output shows the results of each operation. Note that all operations are done using user and group names, with no knowledge of the actual lists of users and groups. The mediator hides all the details.

Accessed through the mediator_exercise() function.

Modules

  • Contains the Group and GroupList structs that manage list of groups, where each group contains a list of users belonging to that group.
  • Contains the UserGroupMediator struct, which mediates between the UserList and GroupList structs.
  • Contains the User and UserList structs that manage a list of users.

Functions

  • Helper method to convert a list of strings to a comma-delimited list in a single string.
  • Example of using the “Mediator” design pattern.
  • Helper method to add a number of groups to the Groups list and then add users to the groups. Note that everything here is done with names.
  • Helper method to add a number of users to the Users list.