Back
Module 4 - Object-Oriented Programming Summary
1. Classes and Objects
- A class is a blueprint that defines data and behavior.
- An object is an instance of a class.
- Objects are created using constructors.
- Each object has its own state.
2. Instance Variables (Fields)
- Instance variables store the state of an object.
- Each object has its own copy of instance variables.
- AP CSA prefers the term instance variable.
3. Methods and Behavior
- Methods define actions an object can perform.
- Methods can access and modify instance variables.
- Methods may return values.
- The dot operator is used to call methods.
4. Constructors
- Constructors initialize new objects.
- They share the same name as the class.
- They do not have a return type.
- Classes may have multiple constructors.
5. Encapsulation
- Encapsulation protects object data.
- Instance variables are usually
private. - Public methods control access to data.
- Encapsulation helps maintain valid object state.
6. Invariants
- An invariant is a rule that must always be true.
- Invariants are enforced using constructors and methods.
- They prevent objects from entering invalid states.
7. Static Members
- Static variables belong to the class, not objects.
- Static methods can be called without creating an object.
- Static members represent shared data or behavior.
8. Object References
- Object variables store references to objects.
- Assigning references copies the address, not the object.
- Multiple references can point to the same object.
9. null and Default Values
null means no object is referenced. - Primitive variables have default values.
- Object references default to
null. - Calling methods on
null causes runtime errors.
10. Sentinel Values
- A sentinel value represents missing or unavailable data.
- Common examples:
-1, "none". - Sentinel values are commonly used on the AP exam.
11. Composition (Has-A Relationships)
- Composition models objects that contain other objects.
- This represents a has-a relationship.
- Composition builds complexity from simpler classes.
12. Delegation
- Delegation occurs when an object calls a method on another object it contains.
- Responsibilities remain with the correct class.
13. Reasoning About Object Behavior (AP Focus)
- Track object state changes.
- Watch for shared references.
- Check for
null before method calls. - Understand which object owns which data.
End of Module 4 Summary