You are previewing Beautiful Architecture.

Beautiful Architecture

Cover of Beautiful Architecture by Georgios Gousios... Published by O'Reilly Media, Inc.
O'Reilly logo

Agents: Wrapping Operations into Objects

The basic ideas of agents (added to the basic object-oriented framework of Eiffel in 1997; see also C# “delegates”) can be expressed in words familiar in the functional programming literature: we treat operations (functions in functional programming, features in object-oriented programming) as “first-class citizens.” In the OO context, the only first-class citizens are, at runtime, objects, corresponding in the static structure to classes.

The Agent Mechanism

An agent is an object representing a feature of a certain class, ready to be called. A feature call x.f(u, ...) is entirely defined by the feature name f, the target object denoted by x, and the arguments u, ...; an agent expression specifies f, and may specify none, some, or all of the target and arguments, said to be closed. Any others, not provided in the agent’s definition, are open. The expression denotes an object; the object represents the feature with the closed arguments set to the given values. One of the operations that can be performed on the agent object is call, representing a call to f; if the agent has any open arguments, the corresponding values must be passed as arguments to call (for the closed arguments, the values used are those specified in the agent’s definition).

The simplest example of agent expression is agent f. Here all the arguments are open, but the target is closed. So if a is this agent expression—as a result of the assignment a := agent f, or of a call ...

The best content for your career. Discover unlimited learning on demand for around $1/day.