From 29fdd0d30c1a6d3363b0dc8d55a79d502df8cc7a Mon Sep 17 00:00:00 2001 From: Louis Brandy Date: Mon, 17 Apr 2017 12:23:22 -0700 Subject: [PATCH] Attempt to add an example (that is as non-controversial as possible) of an inheritance hierarchy to C.120 --- CppCoreGuidelines.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 013b8f4..7a2bc7e 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -6108,7 +6108,27 @@ Do *not* use inheritance when simply having a data member will do. Usually this ##### Example - ??? Good old Shape example? + class DrawableUIElement { + public: + virtual void render() const = 0; + // ... + }; + + class AbstractButton : public DrawableUIElement { + public: + virtual void onClick() = 0; + // ... + }; + + class PushButton : public AbstractButton { + virtual void render() const override; + virtual void onClick() override; + // ... + }; + + class Checkbox : public AbstractButton { + // ... + }; ##### Example, bad