What is the difference between the fox and the crow, on the one hand, and
the cheese, on the other? Of course, the fox and crow are animate, and the
cheese is inanimate. Animate things include agents, which observe changes in
the world and perform their own changes on the world. Inanimate things are
entirely passive.
But if you were an Extreme Behaviourist, you
might think differently. You might think
that the fox, the crow, and the cheese are all simply objects, distinguishable
from one another only by their different input-output behaviours:
If the fox sees the crow and the crow has food in its mouth,
then the fox praises the crow.
If the crow is praised by the fox,
then the crow sings.
If the cheese is in the crow’s beak and the crow sings,
then the cheese falls to the ground.
If the cheese is next to the fox,
then the fox picks up the cheese.
Extreme Behaviourism was all the rage in
Psychology in the mid-20th century. It has been the rage in
Computing for approximately the past twenty years, in the form of Object-Orientation.
It’s easy to make fun of yesterday’s Extreme Behaviourists. But it’s not so easy to dismiss today’s Object-Orientated Computer Scientists and Software Engineers. Object-Orientation today dominates every aspect of Computing: from modelling the system environment, through specifying the system requirements, to designing and implementing the software and hardware.
For a while in the 1980s, it looked as though Computational Logic might come to occupy the central role in Computing that Object-Orientation occupies today. Unfortunately for Logic, it was Object-Orientation that won the day.
If we can understand what makes OO so attractive in Computing today, then we might be able to apply the lessons we learn, to improve the suitability of Computational Logic, not only for Computing, but for Human Reasoning as well.
In the object-oriented way of looking at things, the world consists of encapsulated objects, which interact with one another through their externally manifest input-output behaviour. There is no difference in this respect between an intelligent agent and an inanimate object. An agent is just another object embedded in the world. Object-Orientation turns our earlier picture of the relationship between an agent and the world:
outside in:
In this picture, objects correspond to individuals in the logic-oriented way of looking at the world. They are semantic rather than linguistic entities. However, whereas in traditional logic static relationships among individuals are the primary concern and dynamic behaviour is only secondary, in object-orientation it is the other way around - behaviour is primary and static relationships are secondary and relatively unimportant.
With logic embedded in the thinking component of an intelligent agent, change is dealt with at both the semantic and linguistic levels. At the semantic level it is dealt with by the dynamics of the agent’s observation-thought-action cycle. At the linguistic level it is represented in the agent’s mental language of goals and beliefs, using for example modal logic, the situation calculus or the event calculus.
With objects, change is dealt with primarily at the semantic level. Objects, both animate and inanimate, interact with one another by sending and receiving messages. Receiving a message corresponds to an agent’s observing the current state of the world. Sending a message corresponds to an agent’s performing an action on the world.
With objects, changes can occur simultaneously in different parts of the world, independently and concurrently, without affecting other parts of the world. The event calculus has a similar view of change. But in the event calculus this view is linguistic - talking about change, without actually doing it. In object-oriented systems, these changes actually take place.
Taking account of the dynamic nature of objects, our object-oriented picture of the world should look more like this:
For example, in the object-oriented version of the story of the fox, crow and cheese, the various actions and events are messages between objects. The obvious candidates for sending and receiving these messages are the fox, crow and the cheese:
Advocates of object-orientation regard it as a natural way both to view the natural world and to construct artificial worlds. Systems engineers, in particular, construct complex systems by combining objects, to achieve some overall goal. Typically, the component objects, which make up the system, are themselves sub-systems, like thermostats, printers, computers, cars and airplanes, which are composed in turn of other, simpler objects.
An object consists of a local state, which is a collection of current values of attributes, and a collection of methods, which the object uses to respond to messages or to compute values of attributes. Both of these are encapsulated within the object, hidden from other objects.
Encapsulation of an object’s methods is an inherent property of the natural world, because no object can tell for sure what goes on inside another object. In theory, if you could get inside another object, you might discover that it is just like you. Every object - bear, tree, river, mountain or stone - might have a spirit, which is its internal mental state. Contrariwise, you might discover that no other object, other than yourself, has any kind of internal state whatsoever.
Encapsulation of methods serves a different function for artificial worlds. It reduces the complexity of constructing complex systems from component objects, because the engineer needs to take into account only the external behaviour of the components. Furthermore, should one of the components of a functioning system become defective or obsolete, it can be replaced by a new component that has the same external behaviour, without affecting the overall behaviour of the system.
Object-orientation does not distinguish between an object’s external and internal state. All values of the attributes of an object are encapsulated inside the object. The only way to find the value of an attribute is by sending a message to the object asking for the value and by receiving a message from the object telling what the value is. I will argue later that this is too extreme.
However, in another respect, object-orientation is less extreme than extreme behaviourism. When an engineer constructs an object-oriented system, the engineer needs to get inside the system, both to combine pre-existing component objects and to create new objects from scratch.
To create an object, the engineer needs to initialise the values of its attributes and implement its methods. The values of attributes in this initial state can be given explicitly at the time of creation or can be derived by means of methods.
The common OO languages used for implementing methods are typically procedural languages with a syntax inherited from pre-OO programming languages. Unlike logic, these languages do not have a declarative semantics, because they make no attempt to represent the world around them.
However, even when methods are implemented in procedural programming languages, it is natural to express their specifications in logical form. These specifications have the form of condition-action rules in declarative mood:
If object receives message of form R
then object sends message of form S.
For example:
If the fox receives a message that the crow has cheese in its mouth,
then the fox sends a message of praise to the crow.
If the crow receives a message of praise from the fox,
then the crow sends a message of song.
If the cheese receives a message of song from the crow
then the cheese sends a message of falling to the ground.
If the cheese sends a message that it is next to the fox,
then the fox sends a message that she picks up the cheese.
The methods by means of which these specifications are implemented inside an object can be programmed in different ways. They can also be implemented, as we will discuss later and as should be obvious to the reader already, by means of goals and beliefs expressed in logical form.
Object-orientation prides itself on making it easy for the engineer to create new objects by instantiating more general classes of objects, inheriting methods associated with those classes.
For example, an engineer might create a new fox by creating an instance of the general class of all foxes. The class of foxes as a whole might have general methods for dealing with such messages as the sight of another animal having food and the appearance of food within its grasp. It might also have typical values for such attributes as the colour of its fur and the shape if its tail. The new fox could then inherit these methods and values of attributes with little or no modification, possibly with the addition of certain special methods and attributes unique to itself.
Classes are organised in taxonomic hierarchies. So for example, the class of all foxes might inherit most of its methods and attributes from the class of all animals. The class of all animals might inherit them, in turn, from the class of all animate beings; the class of all animate beings might inherit them from the class of all material objects; and the class of all material objects might inherit them from the class of all things.
Objects and classes have different kinds of existence. Objects are concrete individuals, which typically exist in time and undergo change of state. Classes are abstract individuals, which are timeless.
For example, in the story of the fox and the crow, the cheese changes state in response to local events that take place around it:
These changes of state are generated by methods inherited from the general class of all cheeses, some of which, like the propensity to be in the air after starting to fall, are inherited in turn from the class of all material things. However, the classes themselves do not change state in the same way.
OO systems are semantic rather than linguistic entities. As a consequence, objects need not have any memory of the past. When an object changes state, the change generally wipes out the previous state and replaces it with the new one.
In contrast, logical representations of change describe changes of state without actually performing them. Therefore, in addition to recording the current state of an object, they can record previous states, as well as predict and explore future ones.
There is an obvious way to reconcile logic and objects: simply by using logic to implement the methods associated with objects and classes of objects. A typical implementation of this logical kind might consist of maintenance goals and beliefs, which eventually reduce goals to action sub-goals, including messages to other objects. For example:
Goal: If I receive message of form R
then solve goal G.
Beliefs: G if conditions.
…
G’ if other conditions and I send message of form S.
etc.
Creating a new object by instantiating a class then becomes a simple matter of logical instantiation, substituting a concrete term (such as “ I ”) for an abstract term (such as “any fox”), possibly adding specialised methods and assigning explicit values for some of the object’s attributes.
Logic, used to implement methods in this way, can enhance the power of object-oriented systems. Some, intelligent objects can use logic not only to react to incoming messages and to reduce goals to sub-goals, but also to represent the world, generate alternative courses of action and derive their likely consequences. Other, less intelligent objects can also use logic as their higher-level language of implementation. For purposes of efficiency, these higher-level implementations can be compiled into lower-levels, including hardware. Conversely, lower level implementations can sometimes be decompiled into logical form, to improve and reason about the behaviour of individual objects and collections of objects.
Combining logic and object-orientation can also enhance our logic-based agent model. Most importantly, it provides a framework for extending single logic-based agents to multi-agent systems, by embedding agents in a shared semantic structure. Different objects in this structure can have different degrees of intelligence and different degrees of activity.
The OO semantic structure is one in which objects can change state concurrently in different parts of the world,
independently and without affecting other objects. These changes can take place
destructively, without leaving any record of the past. However, in addition to
such real changes taking place externally in the semantic structure, an
intelligent agent can use logic internally to represent changes, without actually
performing them. These internal representations of change are not destructive
in the same way that external changes destroy earlier states of the world.
To achieve these benefits, we do not need to abandon the distinction made in logic between world structures and their linguistic representations - nor the view that world structures consist of individuals, possibly including events, and of relationships among individuals. On the contrary, we may need to abandon the extreme version of OO, which insists that all attributes of individuals are encapsulated and that all interactions are messages.
Consider, for example, yet again the story of the fox and the crow, and in particular the fox’s observation that the crow has the cheese. In the strict OO version of the story, the observation is a message sent to the fox by another object. But what object is it? The obvious candidates are the crow and the cheese. But clearly the crow object has no goal to achieve in sending such a message to the fox, and the cheese object has no real goals of any kind. Even if one of them were responsible for sending the message, why send it only to the fox? Why not send it to all the other creatures in the area as well?
In our earlier version of the story and in our logic-based agent model more generally, the fox and the crow, but not the cheese, are both agents, and they interact with one another, not by sending messages, but by observing the world and by performing actions on the world. The actions they perform might be observed by other agents in the area.
It seems to me that object-orientation has little new to contribute to our understanding of the story, except to remind us that
· it is important to distinguish between the world and any representations that agents may have of the world;
· it is useful to understand the world in terms of hierarchies; and
· the internal methods agents use to interact with the world are encapsulated, so that they can not be observed directly by other agents.
OO has another virtue, namely that it shows us how to construct artificial worlds in which separate objects can change state concurrently and independently. But this is not relevant in the story of the fox and the crow, where we are only interested in telling a story, and not in constructing a world.
However, comparing logic with OO, it seems that OO goes too far - encapsulating all relationships among individuals inside objects. Thus, the fact that the crow has the cheese at the beginning of the story is encapsulated inside one or both of the crow and the cheese objects, accessible to other objects only by sending and receiving messages.
The alternative is to embrace a less extreme form of object-orientation, in which only those individuals that actively change state are regarded as objects, and only the methods they use to interact with the world are encapsulated. Relationships among objects and other kinds of individuals are not encapsulated, but are manifest in the external world.
Objects, in this more moderate form of OO, interact with the world, not only by sending and receiving messages, but more generally by observing relationships in the world and by performing actions that change relationships in the world. Messages can be viewed as speech acts, in which one object performs a special kind of action whose effects are intended for observation by another object.
Other individuals, like classes, events, numbers and time points, can partake in relationships without being coerced into encapsulated objects.
This moderate form of object-orientation is compatible with our logic-based agent model. It liberalises our notion of agent, to include more primitive kinds of encapsulated object. It enriches our notion of the agent’s environment, to include, not only simple individuals and relationships, but individuals that are objects, which can change state concurrently using encapsulated methods, which are hidden from the external world.
There are several other Computing paradigms that subscribe to similarly moderate variants of object-orientation. These include semantic networks and frames, developed as knowledge representation formalisms in Artificial Intelligence, and the entity-relationship model of databases.
Semantic networks represent the world as a web of relationships among individuals. For example, the network representing the initial state of the story of the fox and the crow might like this:
Here nodes represent individuals, and arcs represent binary relationships, between pairs of individuals. The representation can be extended to non-binary relationships.
Semantic network representations are object-oriented, in the sense that all the facts about an individual are located in a single place, namely surrounding the node that represents the individual. These facts are represented by the arcs connected to that node and by the other nodes to which those arcs are also connected.
However, in contrast with orthodox object-orientation, relationships are represented only once, but are connected to all the individuals that participate in the relationship. Moreover, they are visible to the outside world, and not encapsulated inside objects.
Semantic networks have also been used to represent dynamic information, by reifying events. For example:
agent
Here the semantic network terms “object” and “agent” are only loosely associated with our notions of object and agent. The term “agent” is analogous to the subject of an English sentence, and the term “object” is analogous to the object of an English sentence.
Semantic networks have also been used to represent hierarchies of classes. For example:
are simply graphical representations of atomic sentences. Like sentences of logic, when they are used to represent dynamic information by reifying events, they represent change without performing it.
On the other hand, semantic networks are like semantic structures in the sense that they represent only atomic facts, rather than more general regularities. Although several extensions of semantic networks have been developed to represent regularities, these extensions are not convincing.[1]
Nonetheless, semantic networks show that it is possible to use objects to structure atomic representations of the world and not only to structure the world itself. They also show that it is possible to subscribe to moderate forms of OO, in which objects structure our understanding of the world without hiding everything inside themselves. Frames and entity-relationship databases are similar in this respect.
Semantic networks are one way objects can be
used to structure the representation of the world. Objects can also be used to
structure more general linguistic representations.
We noted, already in Chapter 1, that sentences in logic can be written in any order. However, some sequences of sentences can be much easier to understand than other sequences. Grouping sentences into sets of sentences about objects is one way to make sentences easier to understand.
For example, we can group the atomic sentences describing the beginning of the story of the fox and the crow into the sets of sentences:
The crow: The crow has the cheese.
The crow is in the tree.
The tree: The tree is above the ground.
The fox: The fox is on the ground.
Of course, we can also group the same sentences by means of other objects:
The cheese: The crow has the cheese.
The tree: The crow is in the tree.
The ground: The tree is above the ground.
The fox is on the ground.
To find a good organisation, it is necessary to decide which objects are the most important.
Natural languages, like English, take object-orientation a step further, by employing grammatical forms in which the beginning of a sentence indicates its topic and the following part of the sentence expresses a comment about the topic. This form often coincides with, but is not limited to, the grammatical structuring of sentences into subjects and predicates.
The two forms of object-orientation – grouping sets of sentences by object and structuring individual sentences by object – are often combined in practice. Consider, for example, the pair of English sentences[2]:
The prime minister stepped off the plane.
Journalists immediately surrounded her.
Both sentences are formulated in the active voice, which conforms to the guidelines for good practice advocated in most manuals of English style.
The two sentences refer to three objects, the prime minister (referred to as “her” in the second sentence), journalists and the plane. The prime minister is the only object in common between the two sentences. So, the prime minister is the object that groups the two sentences together. However, the topic changes from the prime minister in the first sentence to the journalists in the second.
Now consider the following logically equivalent pair of sentences:
The prime minister stepped off the plane.
She was immediately surrounded by journalists.
Here, not only do the two sentences refer to a common object, but they also have the same topic. However, the second sentence is now expressed in the passive voice. Despite this fact and despite its going against a naïve interpretation of the guidelines of good writing style, most people find this second pair sentences easier to understand. This seems to suggest that people have a strong preference for organising their thoughts in object-oriented form, which is stronger than their preference for the active over the passive voice.
Object-orientation is not the only way of structuring and ordering sentences. In both of the two pairs of sentences above, the sentences are ordered by the temporal sequence of events.
Now consider the following sequence of sentences:
The fox praised the crow.
The crow sang a song.
The cheese fell to the ground.
The fox picked up the cheese.
Here the sentences are grouped by temporal proximity and ordered by temporal sequence. Individual sentences are structured, not by object, but by agent, as reflected in the use of the active voice.
It’s important to keep things in perspective. Object-orientation isn’t everything. In the case of English, it has nothing to do with the content of individual sentences, but it is one way to group and structure sentences. Compared with logic, OO is like the index of a book, and logic is like the language in which the book is written.
Compared with logic, the main attraction of OO is that it shows us how to construct artificial worlds in which individual objects can change state concurrently and independently from other objects. It facilitates constructing new objects from existing ones by encapsulating methods, to reduce complexity and to improve maintainability.
However, compared both with logic and with more moderate variants of OO, such as semantic networks, extreme OO takes encapsulation too far. Instead of hiding attributes and relationships between individuals inside objects, it would be more natural to make them visible to the outside world. Instead of treating all individuals as encapsulated objects, objects should be restricted to individuals that interact with the world.
Extreme OO also takes the message passing metaphor too far. Instead of forcing all interactions between objects and the world to be messages, it would be more natural for agents and other objects to interact with the world by making observations and performing actions.
Computational logic can be reconciled with both extreme and moderate forms of OO, by using it as a higher-level language for implementing methods and for defining classification hierarchies. Although we have not discussed the possibility in this chapter, it can also be used by a system designer to show that a collection of objects achieves some over-all goal.
Semantic networks and natural languages such as English show that OO is not restricted to modelling semantic structures, but can also be used to structure representations of the world. The example of English, in particular, shows that, in the area of linguistic representations, logic and OO have different concerns. Logic is concerned with representing the world, whereas OO is only concerned with one way of structuring representations. As we have seen, OO needs to be combined with other ways of structuring representations, in order to be useful. It would be interesting, for example, to see how OO might be used to structure a collection of sentences as complex as those that make up this chapter.