7.1 Using a class to encapsulate data and processing
Class design is influenced by the SOLID design principles. The Single Responsibility and Interface Segregation principles offer helpful advice. Taken together, these principles advise us that a class should have methods narrowly focused on a single, well-defined responsibility.
Another way of considering a class is as a group of closely-related functions working with common data. We call these methods for working with the data. A class definition should contain the smallest collection of methods for working with the object’s data.
We’d like to create class definitions based on a narrow allocation of responsibilities. How can we define responsibilities effectively? What’s a good way to design a class?
7.1.1 Getting ready
Let’s look at a simple, stateful object – a pair of dice. The context for this is an application that simulates a simple game...