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

Represents a user with a name. More...

Collaboration diagram for User:
Collaboration graph

Public Member Functions

 User (string name)
 Constructor.
 
override bool Equals (object? obj)
 Override to compare a User or string to this User.
 
override int GetHashCode ()
 Generate a hash code for this instance.
 

Properties

string Name [get]
 The name of the user (read-only).
 

Detailed Description

Represents a user with a name.

Definition at line 25 of file Mediator_User_Classes.cs.

Constructor & Destructor Documentation

◆ User()

User ( string  name)
inline

Constructor.

Parameters
nameThe name of the user to assign.

Definition at line 31 of file Mediator_User_Classes.cs.

References User.Name.

Member Function Documentation

◆ Equals()

override bool Equals ( object?  obj)
inline

Override to compare a User or string to this User.

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

Definition at line 47 of file Mediator_User_Classes.cs.

References User.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 User instance.

Definition at line 71 of file Mediator_User_Classes.cs.

References User.Name.

Property Documentation

◆ Name

string Name
get

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