Free Online Flashcard Deck

7 Composition and Object Collaboration Free Online FlashCards

Study 7 Composition and Object Collaboration with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is composition in object-oriented design?

Back

Composition builds an object from other objects that provide needed services, rather than relying primarily on superclass extension.

02
Front

What relationship does composition represent?

Back

A has-a relationship means one object contains or uses another object as a part or collaborator, such as a Car having an Engine.

03
Front

What is object collaboration?

Back

Object collaboration is the interaction among objects that divide a responsibility and request operations from one another.

04
Front

How does encapsulation support collaboration?

Back

Encapsulation hides internal state and requires other objects to use defined operations instead of accessing that state directly.

05
Front

Why should a collaborator have a small interface?

Back

A collaborator should expose a small, stable interface so clients depend on meaningful operations rather than unnecessary implementation details.

06
Front

What is delegation?

Back

Delegation occurs when an object receives a request and passes part of the work to a collaborator that owns that behavior.

07
Front

When can delegation become harmful?

Back

Delegation is most valuable when the collaborator represents a meaningful, independently replaceable concept; pointless forwarding may indicate unclear boundaries.

08
Front

What relationship does inheritance represent?

Back

Inheritance represents an is-a relationship in which a subtype should be usable wherever its superclass is expected.

09
Front

How does composition support independent variation?

Back

Composition lets behavior vary independently by supplying different collaborator implementations, such as interchangeable pay policies.

10
Front

Why can composition reduce coupling?

Back

Composition can lower coupling because a class usually depends on a collaborator's interface rather than its implementation, protected state, or superclass decisions.

11
Front

How does composition improve testing?

Back

Composition improves testing by allowing a real external service to be replaced with a small fake or mock, such as a fake PaymentGateway.

12
Front

How can composition support runtime configuration?

Back

A collaborator can be supplied through a constructor or setter, allowing implementation selection based on configuration, environment, or user choice.