From the course: Object-Oriented Programming with C++
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Overriding and extending functionality - C++ Tutorial
From the course: Object-Oriented Programming with C++
Overriding and extending functionality
- [Instructor] Let's talk about method overriding. So far, we've seen how product review overrides the display details method to show additional product information, but overriding methods isn't mandatory. For example, look at the getter methods in our product review class. We're perfectly fine with the base review classes, getters and setters for the rating title and text so we don't override them. This is a key point about inheritance. It's primarily about reusing code, not changing it. However, sometimes we do need to modify behavior. Let's look at different ways to override methods. First, our current approach with display details, which currently is extending the base behavior. First, showing the basic review information, then adding product details, the product ID and the category. We could also completely replace the base behavior. For example, like this. Running this version will produce a different output. Note, that we no longer call the base classes display details method…
Contents
-
-
-
-
-
Why reinvent the wheel?3m 12s
-
(Locked)
Extending classes4m 37s
-
(Locked)
Access control in inheritance4m 1s
-
(Locked)
Overriding and extending functionality2m 11s
-
(Locked)
Multiple inheritance2m 22s
-
(Locked)
Multiple inheritance pitfalls6m 32s
-
(Locked)
Challenge: RPG character system2m 25s
-
(Locked)
Solution: RPG character system1m 35s
-
-
-
-