mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 04:44:34 +03:00
Attempt to add an example (that is as non-controversial as possible) of an inheritance hierarchy to C.120
This commit is contained in:
@@ -6108,7 +6108,27 @@ Do *not* use inheritance when simply having a data member will do. Usually this
|
|||||||
|
|
||||||
##### Example
|
##### 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
|
##### Example, bad
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user