Objects consist of: - Answers Type
- what class was used to create this object
Name
- an identifier that can be used with a program to distinguish one object from another created
with the same class
Member data
- the STATE of the object
Member function
- the BEHAVIOR of the object
DDU Design - Answers "Declare, Define, Use"
Declare- Declarations specify an interface, which illustrates the "shape" of a class
Define- Definitions specify implementation details
Use- Interacting with the interface to perform a function
We can declare member data (state) or member functions (behavior) as: - Answers PUBLIC- can
be accessed from outside of an object
PRIVATE- can only be access from within an object
"Users" do NOT have access to private members, which are related to implementation details
they shouldn't have to care about
What members make up its interface? - Answers the PUBLIC members
, What members make up the part of your code that only the authors of the class can see? -
Answers the PRIVATE members
What should the "default" protection level of object members be? - Answers private members
Why are private members referred to as "hidden" - Answers code that uses an object cannot
"see" those members
Why hide data? - Answers 1. Simplify object usage for the users
2. Minimize information requirements
- what if the entire electrical specification for your house was available to everyone who wanted
to plug in a lamp?
3. Security
- what if anyone who wanted to plug in the lamp had access to the breaker and could turn off
your electricity
4. Decoupling*
- What if every time lamp technology improved you had to renovate your house?
Why hide data? - Answers
What does a class declaration do? - Answers gives interface to the users of the class
- shows (1) what an object will look like and (2) what its available functions are
- no implementation details
- each variable declaration specifies its type
- each function declaration tells you how to use it (not how it works!)
give an example of a class declaration (dog.h) - Answers #include <string>
using namespace std;
class Dog
{
public:
//public behavior