Exercise: Decorated teacher

In this exercise you must apply the Decorator Design Pattern - twice!

Before you start

Read and understand the example DecoratedBook.

In this exercise you must make something very similar.

Getting started

In Visual Studio create a new Solution, type Console Application. Name the solution DecoratedTeacher.

Teacher class

Create a class Teacher with properties like Name and Salary.

And methods like ToString() and Equals(Object obj).

ITeacher interface

Extract an interface from the class Teacher. Name the interface ITeacher.

Visual Studio (or rather Resharper) can help you extracting the interface.

UnmodifiableTeacher class

Create a class UnmodifiableTeacher. This class must implement the interface ITeacher, and have a reference to an object of type ITeacher.

All modifying methods and properties must throw NotSupportedException.

Unit testing

Unit test UnmodifiableTeacher.

For inspiration refer to the DecoratedBook example.

Do not forget to test the Equals(Object obj) method.

See that you test has good coverage.

ThreadSafeTeacher class

The Teacher class is not thread safe.

Create a class ThreadSafeTeacher. This class must implement the interface ITeacher, and have a reference to an object of type ITeacher.

The class must be thread safe: Use lock(...) { ... }

Unit testing

Unit test ThreadSafeTeacher.

For inspiration refer to the DecoratedBook example.

Do not forget to test the Equals(Object obj) method.

See that you test has good coverage.