(This question is more suitable for people with access to the book, it is difficult to put them in context otherwise)
I read the book “GoF Design Templates” and the sentence, which confuses me a bit, in the section “Creation Templates → Prototype-> Code Example” (p. 124).
At the bottom of the page there is an implementation for BombedWall , which, as I understand it, is a specific prototype, since it inherits from Wall and redefines the virtual function Clone() . BombedWall also defines another HasBomb() method, unknown to any clients using the normal Wall interface.
The only way to save BombedWall in MazePrototypeFactory (Prototype client) as Wall* (returns from BombedWall::Clone ) and the only way to get to HasBomb() after that, as far as I can understand, is to do downcast on Wall* to BombedWall* (dynamic or static, depending on whether I know the type), and then I can access the HasBomb() method.
It all seemed beautiful to me; but then the author says (same page, last sentence, second paragraph):
"Customers will never have to lower the Clone return value to the desired type."
What? Then how can I get to HasBomb() ?
Something is missing me ...
source share