P

PrepStack

Relationships Between Classes

Classes (blueprints for objects) work together, and the kind of link says who owns whom. "Has-a" means one object holds another: association (a lasting link), aggregation (a group whose members can live without it) and composition (a whole that owns its parts). "Is-a" is inheritance: a class building on another class. Interviewers ask the differences and also ask why "composition over inheritance" is common advice.

After this section you can name each link, show it in Java, and explain a case where inheritance breaks and an object kept inside another fixes it.

Topics in this section