Software development for enterprise systems
Software development for enterprise systems

This free course is available to start right now. Review the full course description and key learning outcomes and create an account and enrol if you want a free statement of participation.

Free course

Software development for enterprise systems

6.4 Collaborating objects

The objects that comprise a program collaborate with one another to fulfill the functions of the system that the program represents. Collaboration occurs when one object requests a service from another object in order to perform some task. To fulfill a particular collaboration, each object takes on a different role. The object that makes the request is called the client, and the object that receives the request (and provides the service in response) is called the server. The request is communicated to the server from the client by message passing. The client sends a message to the server which on receipt executes the operation with the same name and signature as the message. When the server has completed the execution of its operation it returns a message answer to the client. Both the message and message answer may convey data between the objects The signature of the operation is the specification of the type of the arguments and of the result of the operation, e.g. create (name: String, rate: Money, ensuited: Boolean): Room. For brevity, parameter names can be omitted, e.g. create (String, Money, Boolean): Room.

Figure 5 shows the collaboration between Room and Person objects (from the hotel example in Figure 4) where the Room object requests that the Person object linked to it provides the value associated with its name attribute. The Room object, as the client, sends the getName message to the Person object which, as the server, executes the getName operation on receipt of the message. When the Person object has completed the execution of the getName operation it returns the value associated with its name attribute to the client as the message answer.

Figure 5
Figure 5 A collaboration between Room and Person objects

The notation used in Figure 5 is the UML notation for sequence diagrams. Each box represents an object.

For a client object to collaborate successfully with a server object, two conditions must be met:

  1. the client must know the identity of the server (to be able to send messages to it);

  2. the server must understand the message, i.e. it must have an operation with the same name and signature as the message.

Exercise 8

Consider a situation where an Account object provides a debit service by executing the operation debit with the signature debit(amount: Money), and a Bank object wants to debit an amount of 50 from that Account object. Identify the client, the server and the message in this collaboration.

Discussion

Solution

The Account object is the server, the Bank object is the client, the message is debit(50); there is no message answer as the debit operation does not return a value. (However, it will return the flow of control on completion of the operation.)

The public operations that are made available to clients are what matters in the use of an object, rather than any private data it may happen to store internally to represent its state. The set of public operations that can be executed by an object is called its protocol or interface. We shall use the terms interface and protocol interchangeably to refer to the set of behaviours or operations an object offers. An Account object is likely to have the following operations in its protocol: getBalance, debit, and credit.

By convention, when the name of an operation is made up of more than one word, the second and subsequent words have initial upper-case letters, e.g. getBalance.

M885_1

Take your learning further

Making the decision to study can be a big step, which is why you'll want a trusted University. The Open University has 50 years’ experience delivering flexible learning and 170,000 students are studying with us right now. Take a look at all Open University courses.

If you are new to university level study, find out more about the types of qualifications we offer, including our entry level Access courses and Certificates.

Not ready for University study then browse over 900 free courses on OpenLearn and sign up to our newsletter to hear about new free courses as they are released.

Every year, thousands of students decide to study with The Open University. With over 120 qualifications, we’ve got the right course for you.

Request an Open University prospectus