CSE 332 Studio Session on Design Patterns in C++
provide a vocabulary for identifying and describing both common design problems and
known reusable approaches to solving them.
In this studio you will gain experience applying design
patterns relevant to several common design problems that arise in C++ programming, at an introductory
level. Each design pattern has (at least) a name, a description of the problem, a solution description, and
contextual factors (such as the pattern’s intent) to consider when selecting or applying the pattern. More
details about design patterns are at
(the patterns are
linked at the bottom of the page) and
In this studio you will again work in small groups, as before students who are more familiar with the
material are encouraged to help those for whom it is less familiar, and asking questions during the studio
sessions is highly encouraged as well.
Please record your answers as you work through the following exercises. After you have finished please
post your answers to the required exercises, and to any of the enrichment exercises you completed, to the
course message board as a reply to my posting titled “Design Patterns Studio”.
The enrichment exercises
are optional but are a good way to dig into the material a little deeper, especially if you breeze through the
Please make sure as you work through these exercises that each team member has a
chance to participate actively – e.g., take turns coding, looking up details, debugging, etc., and
please also refer to the slides and the posted code examples as you work.
PART I: REQUIRED EXERCISES
1. Find your team members in the studio area, sit down at/around and log in to one of the Windows
machines, open up Visual Studio and create a new Visual C++ Win32 Console Application project.
Change the signature of the main function in the source file that Visual C++ generated to match the one
that was specified for the previous studios. Write down the names of the team members who are present
(please catch up anyone arriving late on the work, and add their name) as the answer to this exercise.
struct, with a const pure virtual
method that takes a
reference to an ostream and has a void return type. Derive (via public inheritance) a
struct from the
struct, and override the virtual print method so that it prints out a
message indicating the specific kind of animal it is (Giraffe or Ostrich, respectively). In your main
function, declare a Giraffe object and an Ostrich object on the stack, and push their addresses back into a
vector of pointers to Animals.
Write a for loop that uses the vector’s
operator to call the print method
on each of the objects whose address is stored in the vector, passing
to each call. Build your
solution, fix any errors or warnings, and run your program to make sure the right information is being