Lecture 6-4: Aggregation
A Second Look at Classes and Objects
After reading through Chapter 6, you should be able to
- Explain the difference between an instance member and a static member
- Write overloaded methods and constructors
- Write methods that accept objects as arguments
- Write methods that return references to objects
- Write methods that return copies of objects
- Explain what a copy constructor is
- Explain the concept of aggregation and how a "has a" relationship can exist between classes
- Explain why instance fields that are reference variables must reference objects before they are used to perform operations
- Explain the
thisreference and how to use it to overcome the shadowing of field names by parameter names
- Understand what garbage collection is
- Explain when a class needs to collaborate with another class to fulfill its responsibilities
- Use CRC cards to discover class responsibilities and collaborations
Today's Learning Objectives
- Know what is meant by aggregation
- Know how to overload the constructor method
- Know what the new keyword does and how an object is referenced in memory
Aggregation
Creating an instance of one class as a reference in another class is called object aggregation.
Aggregation creates a "has a" relationship between objects. In the UML class diagram below, the course class has a Instructor and has a TextBook