Conceptly
← All Concepts
βœ‰οΈ

Message Passing

InteractionHow objects cooperate through method calls

Message passing is the idea that objects cooperate by sending requests to one another through method calls instead of reaching into each other's internals. The sender states what it wants; the receiver decides how to fulfill that request using its own state and implementation.

β–ΆArchitecture Diagram

πŸ”„ Process

Dashed line animations indicate the flow direction of data or requests

Why do you need it?

When one object directly edits another object's fields, object boundaries quickly collapse. Encapsulation becomes nominal only, and one object's internal representation leaks into many callers, making future changes expensive.

Why did this approach emerge?

The Smalltalk tradition described objects as independent actors that communicate through messages. Modern languages often present the same idea as ordinary method calls, but the underlying design principle remains that behavior belongs to the receiving object, not the caller.

How does it work inside?

A sender object calls a public method on a receiver object. The receiver inspects or updates its private state as needed, returns a result, and may send further messages to other collaborators to complete the job.

Boundaries & Distinctions

The key difference between message passing and direct data manipulation is where responsibility lives. Message passing keeps responsibility with the receiving object; direct field edits move that responsibility outward into callers.

When should you use it?

Message passing is useful anywhere object collaboration matters, from domain models to service delegation to UI event handling. The tradeoff is that if objects are too fine-grained, a single feature can turn into a long and noisy chain of tiny messages that is hard to debug.

Coordinate domains -- let an order object ask inventory and payment objects for workDrive UI interactions -- forward events from one object to anotherPreserve state hiding -- request behavior instead of manipulating foreign fieldsTrace collaboration -- understand object cooperation as a call flow