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

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