Chapter 22. Class Relationships—Part 1

Difficulty: 5

How are your OO design skills? This Item illustrates a common class design mistake that still catches many programmers.

A networking application has two kinds of communications sessions, each with its own message protocol. The two protocols have similarities (some computations and even some messages are the same), so the programmer has come up with the following design to encapsulate the common computations and messages in a BasicProtocol class.

 class BasicProtocol /* : possible base classes */ { public: BasicProtocol(); virtual ~BasicProtocol(); bool BasicMsgA( /*...*/ ); bool BasicMsgB( /*...*/ ); bool BasicMsgC( /*...*/ ); }; class Protocol1 : public BasicProtocol { public: Protocol1(); ~Protocol1(); ...

Get Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.