From the course: Object-Oriented Programming with C++
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Extending classes - C++ Tutorial
From the course: Object-Oriented Programming with C++
Extending classes
- [Instructor] Looking at our project files, we can see the massive code duplication across our three classes. Let's fix this using inheritance. First, we need to identify what these classes have in common. All three classes share a common set of Review data, the rating, the title, and the text. They also have the same displayDetails public member function plus the getters and the setters for the rating, title, and text member variables. They also share the same validation logic for rating range and string lengths. If we check the implementation of the Review and the ProductReview, the setRating performs the same validations, and in setTitle and setText they call validateAndTrim. Now, our Review class already has all this functionality well implemented. It will serve as our base class, what we call a parent class in inheritance. Now, let's modify ProductReview to inherit from Review. Let me close these files and we'll open the header. First, we must include the review header…
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
-
-
-
-