C++ Classes, Objects, and Methods a class collects data and the methods used to access or change the data Such a collection of data and methods is called an object belonging to the given class Every C++ class consists of members that represent either variables called data members) or functions (called methods or member functions). The member functions of a class are normally used to access or alter the data members
C++ Classes, Objects, and Methods A class collects data and the methods used to access or change the data. Such a collection of data and methods is called an object belonging to the given class. Every C++ class consists of members that represent either variables (called data members) or functions (called methods or member functions). The member functions of a class are normally used to access or alter the data members
Example: For the Life game, the class is called Life, and configuration becomes a life object. We use three methods: initialize)will set up the initial configuration of living and dead cells; print() will print out the current configuration and update will make all the changes that occur in moving from one generation to the next
Example: For the Life game, the class is called Life, and configuration becomes a Life object. We use three methods: initialize( ) will set up the initial configuration of living and dead cells; print( ) will print out the current configuration; and update( ) will make all the changes that occur in moving from one generation to the next
Clients, that is, user programs with access to a particular class, can declare and manipulate objects of that class The specifications of a method, function, or program are statements of precisely what is done Preconditions state what is required before Postconditions state what has happened when the method function or program has finished
Clients, that is, user programs with access to a particular class, can declare and manipulate objects of that class. The specifications of a method, function, or program are statements of precisely what is done. Preconditions state what is required before; Postconditions state what has happened when the method, function, or program has finished
Programming Precept Include precise specifications with every program function, and method that you write Information Hiding By relying on its specifications, a client can use a method without needing to know how the data are actually stored or how the methods are actually programmed. This important programming strategy known as information hiding
Programming Precept Include precise specifications with every program, function, and method that you write. Information Hiding By relying on its specifications, a client can use a method without needing to know how the data are actually stored or how the methods are actually programmed. This important programming strategy known as information hiding
Data members and methods available to a client are called public; further private variables and functions may be used in the implementation of the class but are not available to a client Convention Methods of a class are public Functions in a class are private
Data members and methods available to a client are called public; further private variables and functions may be used in the implementation of the class, but are not available to a client. Convention Methods of a class are public. Functions in a class are private