This chapter explored
techniques that may be used to
structure object-oriented programs.
These techniques may be regarded as
idioms or guidelines augmenting
the mechanisms provided by object-oriented languages.
1
- virtual functions -- scoping, recursion
- invariant properties -- hidden features
- the diamond structure -- hiding realizations
slide: Section 7.1: Composition by inheritance
In section 1,
we looked at the problems
that may occur when employing
virtual functions and explicit scoping,
in particular in the presence of recursion,
how to maintain invariance when using
inheritance,
and we discussed the diamond structure
for the realization of compound objects.
2
- hiding -- functional behavior, interface
- smart pointers -- object management
- abstraction -- interface, realization
- roles -- dynamic switching
slide: Section 7.2: Interaction through delegation
In section 2,
an example was given demonstrating
implicit delegation in C++.
Also, we looked at the notion
of smart pointers.
Delegation underlies the envelope/letter
idiom which allows for separating the
interface of a data type from its
realization.
We also discussed an example
of dynamic role switching,
employing explicit delegation.
3
- gadgets -- require, damage and draw
- events -- interception, callbacks
- MV(C) -- model, view, control
slide: Section 7.3: Indirect cooperation
In section 3,
we looked at some patterns of
cooperation between objects.
The examples were inspired
by solutions employed in the Interviews
user interface development library.
Also, a schematic implementation
of the Smalltalk MV(C) paradigm
was given.
4
- abstract system -- functional behavior
- user interface -- displayer, prompter
- events -- to define interactions
- dependencies -- interconnections between events
slide: Section 7.4: Event-driven control
Finally, in section 4, we looked at an example demonstrating
event-driven control.
Events provide a powerful abstraction
to define the interaction of objects
in response to a user action.
- Discuss the interplay between scoping and recursion
for virtual functions.
- How would you express the invariant behavior
of an employee class?
Explain what problems may occur when adding a bonus to the
salary of a derived manager class.
- Explain how compound objects may
be constructed by employing the diamond structure.
- 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++.
- What is a gadget?
Give an example showing the interaction between a gadget
and a window.
- Characterize the notion of event in a window environment.
Characterize also the interaction between events and the gadget
to which the event is directed.
- Sketch how the Smalltalk MV(C) paradigm may
be implemented in C++.
Give a simple example of its use.
- Explain how events may be used to regulate
the effects of user actions.
Why are events needed?
An invaluable source with respect to idioms and advanced usage of C++
is [Coplien92].
Further, you may consult [KP88] for examples
of applying the MVC paradigm,
and [Henderson93] for examples of employing events.
[Henderson93] also proposes a canonical mapping from a formal
specification language to an implementation in C++.