From the course: Object-Oriented Programming with C++
Why should we hide information? - C++ Tutorial
From the course: Object-Oriented Programming with C++
Why should we hide information?
- [Instructor] Let's examine our current review class. We've created a nice system for storing product reviews, but what if you want to update the rating or fix a typo in the text? Let's try to update the review after it's created. I set its rating to four. And the reviews text to say, "Good." Now I try to run this program. The code doesn't even compile. The member variables we wanted to update are locked away behind private access specifiers. And while this is good for protection, we can't modify them at all. But wait, we can make them public, right? The code now compiles and runs without issues. However, there's nothing to stop the collars from assigning an invalid rating, such as, say, zero, or even six, and they could even set the title or text to empty strings. We've gone from one extreme, no access, to another, unrestricted and uncontrolled access. This was a bad idea, so let's reword the access to private, and remove these lines from the main function. What we need is a controlled way to modify our review data, a way that lets us validate the new values in order to maintain the integrity of our review objects. In the following video, we'll explore how to do this properly.
Contents
-
-
-
-
Why should we hide information?1m 44s
-
(Locked)
Doorways to data: Getters and setters7m
-
(Locked)
Applying the DRY principle6m 56s
-
(Locked)
Challenging const correctness3m 3s
-
(Locked)
Friends3m 9s
-
(Locked)
Challenge: Bank account with audit system1m 33s
-
(Locked)
Solution: Bank account with audit system2m 33s
-
-
-
-
-