Exercise: Composite design pattern

This exercise might not be very realistic - anyway you are going to get some experience on programming using the composite design pattern.

You are supposed to program some classes modeling things you might buy in a supermarket. A common name for things to buy in a supermarket is Stuff, more specifically it is OrdinaryStuff (milk, bread, etc.) and StuffContainer (plastic bags, etc.). A StuffContainer can be empty or hold any number of OrdinaryStuff - or other StuffContainers, that hold ...

As a specification you get some documentation and some unit tests.

Sequence of implementation

IStuff

Make the interface IStuff according to the documentation IStuff

OrdinaryStuff

Make the class OrdinaryStuff according to the documentation OrdinaryStuff

StuffContainer

Make the class StuffContainer according to the documentation StuffContainer and the unit test StuffContainerTest.
Note that you may have to remove (make into comments) some of the lines in the test, if you want to make the test Green before completing the exercise.

Do the individual features in this sequence:

  1. In the class StuffContainer you must declare a field like
    private readonly IList<IStuff> _stuffInContainer = new List<IStuff>();
  2. simple properties: Description, MaxWeight, IsEmpty
  3. ToString
  4. Add
    In this first version of Add do not check if you exceed the MaxWeight. Just Add no matter what
  5. Remove
  6. Weight
    Hint: LINQ might be helpful
  7. Add
    In this second version of Add you should check if the Add exceeds the MaxWeight.
  8. Count
    This might require some recursive method calls.
  9. Implement IEnumerable<IStuff> (should be easy)
  10. Extra: Contains
  11. Extra: Add
    In this third version of Add you must check that a Container is not added to itself directly or in-directly. Hint: use Contains.