mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Merge pull request #892 from lbrandy/master
Example of an inheritance hierarchy for C.120.
This commit is contained in:
commit
540c393501
|
@ -6183,7 +6183,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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user