Object Oriented Programming using C#

(backadmin) #1

Object Oriented Programming using C#
Case Study


namespace MessageManagerSystem.Clients
{
[Serializable]
public class ClientBook
{
private SortedDictionary<int, Client> clients;
public SortedDictionary<int, Client> Clients
{
get { return clients; }
}
public ClientBook()
{
clients = new SortedDictionary<int, Client>();
}
public ClientBook(SortedDictionary<int, Client> clients)
{
this.clients = clients;
}
public void AddClient(int clientID, Client newClient)
{
try
{
clients.Add(clientID, newClient);
}
catch (ArgumentException)
{
throw new ClientAlreadyExistsException
(“ClientBook.AddClient(): a client with this ID
already exists in system ID:” + clientID);
}
}
public Client GetClient(int clientID)
{
try
{
return clients[clientID];
}
catch(KeyNotFoundException)
{
throw new UnknownClientException
(“ClientBook.GetClient(): unknown client ID:” +
clientID);
}
}
}
}

The code above shows the constructors to create a ClientBook object which is a sorted dictionary of ClientID, Client
objects and the other methods required by the ClientBook class. Further discussion of this is provided below.

Free download pdf