Delegation
Instructor's Guide
intro,
inheritance,
delegation,
cooperation,
events,
Objectives
This section shows how delegation may be employed to
hide realizations, to implement smart pointers and
to switch dynamically between roles.
Points to emphasize
- hiding -- functional behavior, interface
- smart pointers -- object management
- abstraction -- interface, realization
- roles -- dynamic switching
Hints
Implicit delegation may be implemented in C++
by overloading the de-reference operator.
Overloading is a powerful, yet debatable feature of C++.
Discuss the trade-offs between flexibility and built-in support.
Questions
- Explain how the functionality of a class may be
made accessible through an arbitrary interface class
by employing implicit delegation.
- What are smart pointers? Why are they useful?
How would you implement them?
- Sketch how you would implement dynamic role switching in C++.
Comments
Invite students to try out some simple examples
themselves.
How overloading the de-reference operator works in detail
is in my experience quite hard to explain.
Experience does wonders.