Summary
The topic of best practices when defining types in C++ is vast, and we have covered a great deal in this chapter to help you move toward creating classes that are robust and maintainable. We covered encapsulating data by using the private
keyword to ensure that we decide how that data is accessed. We looked at getters and setters to give access to data and modify it in a way that can be validated. We also looked at how references can be used to give access to our data and modify it directly, and at how we can return data by value when we only want it to be read or used elsewhere without changing the object's internal data. We found that const
can be used to ensure that any member variables we do not wish to be changed can be marked as such, along with member functions.
In the next chapter, we will look at what can be used to ensure that any dynamic objects we create can be properly destroyed using smart pointers. Pointers are a major part of C++ and come with their...