Object-Oriented Programming Flashcards
What is NOT considered object-oriented?
public data, multiple inheritance, setters/getters, protected or private derivation, friends (excluding operator overloading), spontaneous change to an object’s state
What kind of relationships are there? Describe them.
Contained (“has a”) relationships, using (user awareness), and inheritance/specialized (“Is a”)
Contained: One class contains the object of another class as a data member. Using: Passing the instance of one type as a pointer or reference of another type in a member function argument. Inheritance: Where child class(es) are derived from a parent/base class and the child IS the parent + more.
What is the object’s “state”?
Can the object’s state change?
The object’s state is the collection of all the information held by an object.
A mutable object’s state can change over time, but not spontaneously. The change in the object’s state must be a consequence of methods performed on the object. An immutable object cannot change its state.
What are the “rules” of object-oriented programming?
- Each object has narrow and specific responsibilities.
- Objects can store data based on prior operations.
- No public data.
- An object has a “state”, “operations”, and an “identity”.
- Two or more classes can have the same state and operations but a separate identity.
What are the four parts of object-oriented design?
- Understand the problem from an application perspective.
- List all nouns relevant to the problem.
- Group the nouns together and push up the common.
- Make sure the classes communicate to work together to solve the problem.
To avoid having the state of an object spontaneously change, what do you need to do?
Keep the data in the private or protected sections.
What IS considered object-oriented?
Single inheritance, classes have clear responsibilities but are not bloated, public derivation, private or protected data