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
. Here all the
arguments are open, but the target is closed. So if
agent
fa
is this agent expression—as a result of the
assignment a :=
, or of a call ...agent
f
Get Beautiful Architecture now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.