Object Oriented Programming using C#

(backadmin) #1

Object Oriented Programming using C#
Case Study


Some of the code from this class is shown below :-


namespace MessageManagerSystem.Messages
{
[Serializable]
public class MessageSet
{
private HashSet<Message> messages;
public HashSet<Message> Messages
{
get { return messages; }
}
public MessageSet()
{
messages = new HashSet<Message>();
}
public void AddMessage(Message msgToAdd)
{
messages.Add(msgToAdd);
}
public void Display(IDisplayBoardControl db)
{
db.LoadMessages(messages);
db.Run();
}
public void DailyPurge(ClientBook clients)
{
// code omitted here
}
private bool ToBeDeleted(Message m)
{
return m.HasExpired();
}
}
}

The code above shows the creation of a typed collection of ‘Message’ called Messages and methods to add and display
messages.


The method to display messages requires and object of type DisplayBoardControl to be passed as a parameter. Initially
a DummyBoard object will be provided however when a real display board is purchased then this object will replace the
DummyBoard object. This will have no impact on the code within the Display() method as both objects are of the more
general type DisplayBoardControl. This is another example of the application of polymorphism.


The DailyPurge() method was excluded from the code above so we could concentrate on this method now.

Free download pdf