Exercises

  1. Implement the final stage of the Photo Group application, which involves fetching and displaying an image (extrinsic state) when its thumbnail (intrinsic state) is clicked.

  2. Integrate the Photo Library and Photo Group applications so that commands can be issued as well as photos displayed. Keep track of the two patterns (Composite and Flyweight) and report at the end of the exercise how they fit together.

  3. In the earlier Composite pattern example (Example 3-3), the specification of the Photo Library was read from a file. As an exercise in object initialization, specify the initial state of the library in the program using the same data:

    AddSet Home
    AddPhoto Dinner.jpg
    AddSet Pets     Going down another level
    AddPhoto Dog.jpg
    AddPhoto Cat.jpg
    Find Album      Ensures Garden is at same level as Home
    AddSet Garden
    AddPhoto Spring.jpg
    AddPhoto Summer.jpg
    AddPhoto Flowers.jpg
    AddPhoto Trees.jpg

    (Hint: take these lines out of the data file. The program won't have to change otherwise, as the loop will start processing from the first command it finds in the file, which will be Display.)

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.