Unit 5 Flashcards

1
Q

Why do object modellers concentrate on nouns?

A

The nouns represent the things in the domain being modelled, and things are more stable than actions, which are expressed as verbs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the main criteria for filtering a list of nouns in order to remove inappropriate ones and settle upon a more suitable set of candidate classes?

A

There are three basic criteria that can be applied as follows:
Redundancy;
Not important or independent enough, such as an attribute of another class rather than a class in its own right;
Lack of relevance to the problem domain; either beyond the scope of the desired system, or part of the language used for modelling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain why object diagrams cannot form the basis for a software specification.

A

Object diagrams represent particular states of the system at particular moments in time, whereas a specification must describe all valid states of the system, at all possible times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In a windowing system, a window may be converted to an icon, and back to a full window. What operations can be performed on full windows but not on iconised windows? Would a model containing the classes Icon and FullWindow be able to capture the distinction adequately?

A

Scrolling and maximising can be done on full windows but not on iconised ones. It will be difficult to model the distinction between a full window and its iconised version adequately by using two different classes, since an object (in this case, the window) cannot dynamically change its class. A solution to this problem might be to have a single class in which an attribute makes the distinction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In connection with rooms, the hotel manager’s vocabulary includes the words ‘occupied’ and ‘free’. How might such words be represented in a class diagram?

A

Two ways come immediately to mind: c as an attribute of the Room class; c as an association between the Room and Guest classes. Either is quite acceptable as a way of recording the information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In your model in part (b), will your decision about occupancy change if you have to include the fact that a room must be cleaned before the next guest occupies it?

A

No. The cleaning of a room certainly depends upon whether or not it is occupied, but not on how we choose to model occupancy. (You would include this requirement relating to cleaning in a dynamic model, such as a sequence diagram or state diagram. This will be discussed in a later unit.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Does invoking an operation on an instance of a class always change the object’s state?

A

No. Not all operations are intended to change an object’s state. For example, you might provide an operation on the Guest class to respond with the address for any particular instance (object) of that class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does an attribute of a class represent?

A

An attribute represents a particular property (a named value) of the class that each instance of that class will have. Whatever else the attributes of a class are used for, at any one time they collectively define the state of an instance of the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Does a multiplicity of 1 indicate that there can be no change in the object to which the multiplicity relates?

A

No. It merely means that at any one time there will be exactly one object at that end of the relationship. The attributes, or even the identity, of this object may change over time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If an airline system models flights and pilots, and each flight needs two pilots, would you use a multiplicity of 2?

A

Probably not. There are probably times during the life of a Flight object when fewer than two pilots are allocated, such as when the flight has been scheduled but crew details have not yet been settled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Suppose that each person has a number of wardrobes, and each wardrobe contains an even number of shoes. How would you model the evenness of the shoes?

A

You might use a multiplicity on the association between the classes Wardrobe and Shoe, indicating that valid values were 0, 2, 4, 6, 8 and so on up to some reasonable limit. Alternatively, you could say that a Wardrobe contains an arbitrary number of instances of a class called ShoePair, where each ShoePair contains one left shoe and one right shoe. This approach generalises more easily to situations where the groups are not homogeneous. For example, a table setting contains one knife, one fork and one spoon.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If a model contains role names, do you also need to use association names?

A

No, but it is sometimes convenient to have a name for the association as a whole. For example, you might focus on what is meant by works for, rather than the need to consider both the role employer and the role employee (at the same time).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a navigation expression used for?

A

It provides a way of naming another object or its attributes relative to a starting object, by referring to intermediate role names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a recursive association?

A

A recursive association is an association where both ends terminate at the same class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Imagine you are drawing up the specification for a software system for a petrol station to administer the dispensing of petrol and its associated billing. Consider all the interactions that are involved between driving into the petrol station and departing. What makes the petrol flow? How does the cashier know how much to charge? How does the manager know when to refill the storage tanks? Make a list of all the nouns that you use in describing how various people make use of the system. (You are not required to make judgements about relevance or implementation at this stage.) After you have done that, filter your list of candidate classes. You need to be clear about the reasons for rejecting them.

A

Here is our list, but yours may be different.
arrival,
bill,car,car’s petrol tank,cashier,change, cheque, credit card, customer, delivered volume, departure, fuel cost, fuel delivery, fuel quantity sold, fuel type, holster, manager, nozzle, petrol tank, cap, price display, pump,sale, signature, storage tank for fuel,
trigger, unit fuel cost, volume display.
You can group the rejected nouns from our candidate class list using the following
reasons:
Out of scope – customer, cashier, petrol tank cap, cheque and signature;
Probably out of scope – change and credit card;
An operation – sale, arrival, departure and fuel delivery;
Attributes of something else – car’s petrol tank, unit fuel cost and fuel type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In Figure 1, suppose that Jack checks out of the hotel. What changes would you make to the diagram?

A

The link between jack and room r123 should be deleted. Whether or not the link between jack and theRitz should be removed needs to be checked with the domain expert, because the hotel may wish to retain some link with its guests after they have checked out.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Give examples of different possible interpretations of classes with the names Room and Guest. When would new instances be created, and when would they be destroyed?

A

A Room class might represent physical rooms, which might be created and destroyed as building operations change the number of physical rooms. The instances might represent lettable rooms, whose existence might be related to whether the room was unlettable because of cleaning or repair works. A Guest class could represent a person currently staying in the hotel, which would be created at check in and destroyed at check out. It might represent a person who has stayed at least once, so that they would be created on the first check in and not destroyed on check out, but kept on the books. It might represent a potential guest, such as someone who has reserved but perhaps did not stay. Instances would be created on first contact with the hotel, and perhaps would not be destroyed, or not until they had generated no business for some years.

18
Q

Figure 16 presents a preliminary model for a software system to assist with the administration of a number of orchestras. Study the model and make a list of possible problem areas that would need to be resolved with the domain experts – presumably the orchestra managers.

A

You may have identified other problem areas, but here are nine that we found using some domain knowledge.
1 A player can play for only one orchestra.
2 The model cannot represent an orchestra that currently has no players, such as
during the gap between forming the orchestra and hiring the first player.
3 Is there always a ‘next concert’ – even immediately after a new orchestra has been
created?
4 Does any player ever play multiple instruments?
5 What does ‘instrument’ mean? Does it refer to an instrument type, such as a violin,
or to a particular instrument, such as Susan’s Stradivarius violin? If it means the latter, do we need the concept of ‘instrument type’?
6 The model currently just shows that pieces of music need instruments. Do you
need to say how many of each instrument will be needed?
7 Does a single orchestra give each concert?
8 Is there only one conductor associated with an orchestra? Do you need to distinguish chief conductors from guest conductors? Should Concert have an association with conductors?
9 What is meant by ‘piece’? How many times can an orchestra play each piece?

19
Q

Build a model to show the relationships between a person and their natural parents. Does your model prohibit someone from being his or her own mother? Is your model true for the whole of humanity or just for the people represented in some software system?

A

Figure 17 shows one possible model. There is nothing to say that the people at the end of the relationships are different. Since the non-identity of parent and child is part of the meaning of being a parent, you will need to capture that constraint in some other way. We have shown that every person has a father and a mother. That is true if we include dead people as instances of Person, but is not true if Person represents a living person, or a person in some finite set such as those represented in a computer. This is another example of how vital a project glossary is to relate terms in the class model, such as Person, to one particular meaning in the world. Simply naming a class Person is never enough.

20
Q

When considering attributes, what is the effect of moving from a conceptual model to a specification model?

A

The conceptual model records attributes of classes that will be familiar to a domain expert. For example, a hotel manager will be familiar with the daily rate for a room and whether or not it is occupied. In the specification model, the developer must consider the representation of attributes within a software system. For instance, daily rates for rooms involve money, and you can use a true/false (Boolean) expression to represent the occupancy of rooms.

21
Q

Why is a class model not sufficient to describe a system?

A

A class model is a static model that describes the elements of a system (the classes) and their relationships (the associations), but does not describe the behaviour of the system over time. For this you will need one or more dynamic models. In particular, you need to model the life histories of objects and the interactions between them. The model needs to capture when instances of classes should be created and destroyed.

22
Q

What is meant by navigability? When is this idea useful?

A

Navigability means that it is possible to identify (or ‘reach’) objects in one class from objects in an associated class. The usefulness of this idea is realised during implementation when navigability in one direction alone (unidirectional navigability) can lead to simpler code.

23
Q

In a multi-user operating system, users are allocated passwords. Draw a fragment of a class model to represent this association. Bear in mind that you do not want to be able to identify the corresponding user for a given password. What does this tell you about the representation of the association?

A

Users will want to ‘know about’ their passwords, not the other way round. Figure 23 shows that each instance of the class User will have a collection of references to the appropriate Password objects.

24
Q

What is a qualified association?

A

A qualified association is an association at one end of which there is a qualifier, consisting of one or more attributes. The values of the attributes (taken together) uniquely identify the objects in the class at the other end of the association.

25
Q

Suppose that, in the invoices example shown in Figure 18, invoices have unique numerical identifiers known as invoice numbers. How would you capture this information in a class diagram?

A

You could use a qualified association whose attribute is named invoiceNo in a manner similar to that shown in Figure 25, by attaching the qualifier to the Customer end of the association between Customer and Invoice.

26
Q

Under what circumstances would you want to show an association that is not independent of others in the diagram?

A

If a word describing an association is part of the natural vocabulary of the domain expert, it will be sensible to include it in the model, as otherwise a linguistic gulf will start to open between the domain expert and the system designer. However, if you know that an association is not essential, because it can be derived from other associations, you will also need to record that fact.

27
Q

Build a class model associating companies, libraries and families with people, identifying people by suitable qualified associations. When considering a family, be sure that your model handles twins (multiple children with the same date of birth) and sharing of names between generations (for example, mother and daughter with the same name).

A

Looking from a company’s and a library’s perspective, you can find a way to identify a single person who may be a worker or a member, respectively, as shown in Figure 28. In the case of a family, two or more members of that family may have the same birthday or the same name, but the combination of name and date of birth should be unique. Using two qualifiers (name and birthdate) should uniquely identify a person.

28
Q

What is the difference between inheritance and generalisation?

A

There is no difference between inheritance and generalisation. However, the term inheritance tends to be used by programmers, whereas the terms generalisation and specialisation are used by analysts and modellers.

29
Q

Look again at Figure 30. Will an instance of Account support the addInterest operation?

A

No; addInterest is not part of the interface for the class Account. It is, however, part of the interface for the class SavingsAccount, which is a specialisation of the class Account. Objects of the superclass cannot replace objects of any subclass.

30
Q

In a computer graphical user interface, how might you represent the relationship between a full window and an iconised window from the classes FullWindow and Icon respectively? List the operations that are common to both and those that are peculiar to each.

A
You could introduce a new, abstract class named Window, and let the other classes inherit from it as follows:
Abstract class Window with operation display;
Subclass Icon with operations display and maximise;
Subclass FullWindow with operations display, iconise and scroll.
31
Q

Suppose you are asked to model three different kinds of payment that are allowed at a supermarket checkout. The first method of payment allows a customer to use cash to pay for the items in their shopping basket. The second method of payment, which avoids the need to handle cash, involves a personal cheque that requires a cheque card to guarantee the amount to be paid to the supermarket. The third method of payment involves the use of a credit card, which requires authorisation by the credit card company.

(1) Describe how you would model the details of the different payment methods. (Hint: think about subclasses.)
(2) There are three general reasons that we might have for adding subclasses to a model. See if you can work out what these three reasons are, by examining your answers to part (b) above.

A

(1) Although there are common features, each subclass of Payment needs to be dealt with in a different way. A cash payment is the simplest. A customer uses a combination of bank notes and coins to pay for the sale. Commonly, a customer hands over more cash than is required to cover the cost of a sale, so there is a notion of change to be handed back, which may have to be shown on the till receipt. The other two forms of payment are associated with the exact amount required, so no change is required (we will ignore facilities such as ‘cash back’). A payment by cheque requires the customer to present a cheque guarantee card. You could choose to model a new association to a new class called ChequeCard, or you could simply use a new attribute to record whether a valid cheque card was presented. Payments made by credit card are substantially different from the other two forms of payment because the supermarket must be confident that they will receive the required amount of money. In practice, this might involve a connection to the credit card company for authorisation.
(2) The above discussion illustrates that there are three situations that could lead to the decision to include additional subclasses in a model:
(i) there may be additional attributes of interest;
(ii) there may be additional associations of interest;
(iii) there may be different kinds of behaviour that ought to be represented.
That there are precisely three situations is related to the fact that classes have attributes, operations and associations.

32
Q
Figure 24 shows the class Account with an attribute, called accountNo. Write an
create constraints simply because you
appropriate invariant that limits the values of this attribute to a number composed of a 3-digit branch code followed by a 7-digit identifier.
A

We are not told anything about the range of either branch codes or identifiers, but
we do know that a valid account number has 10 digits as follows:
{accountNo is a 10-digit number, with a 3-digit number at the beginning for the
branch code, followed by a 7-digit identifier}

33
Q

When is an invariant on a class true?

A
The invariant on a class must be true for every object of that class from the time
that object is created to the time it is deleted.
34
Q

What are the risks involved when you try to record all the possible constraints on a
model?

A

The first risk relates to the complexity of the resultant model. If too many constraints are recorded on a model, that model will become difficult to read or comprehend. For each case, you should decide whether or not a given constraint
adds value to your particular model. It may be more appropriately recorded in the glossary.
The second risk relates to the potential increase in the number and complexity of any dependencies that would arise for each additional constraint, especially those among two or more model elements. For example, if an association is constrained in some way, all other paths via association loops must be constrained in the same
way.

35
Q

In a model that contains the classes Adult and Child, where each Child has a
mother and father that are instances of Adult, what constraints might you impose
on relationships between the classes? Express the constraints in English.

A

Every Child must have a mother and father that are instances of Adult. The father
cannot be the mother. A father must be male, and a mother must be female. Both
adults must be older than the child.

36
Q

In the UK, it is a legal requirement that both parties to a marriage are at least 16.
Should this be modelled as an invariant?

A

Almost certainly not. A model is meant to express what the case is about, rather than what it ought to be about. So unless the domain expert agrees that illegal marriages will not need to be represented, our model should allow them.

37
Q

How would you model the constraint in a hotel system that every bill must be paid
with either a cheque or a credit card? How would you extend your model if cash
were to be allowed?

A
Figure 47 shows one way is to use the {xor} notation. However, this can relate only
two associations. If you need to express a three-way constraint in order to allow for the addition of cash payments, for example, you will have to abandon the graphical notation of {xor}, and resort to writing a textual constraint. Alternatively, you could use generalisation to create an abstract Payment class with an association to the class Bill, following the examples in Section 4 of this unit. Then each payment method, such as cheque or credit card or cash, would become a
specialisation of the parent, abstract class Payment.
38
Q

The model in Figure 51 expresses the fact that a train must be associated with two employees: a driver and a guard. By considering the loop of associations, identify a problem with the model, and suggest a constraint that solves the problem.

A

You need to capture the fact that a given employee cannot be both the driver and the guard for a particular train. You can formulate this as a constraint on any class round the loop. For example, the following constraint can be located in the class Train: context Train inv:self.driver self.guard

39
Q

The model in Figure 52 shows that a person takes out a mortgage to buy a house. A person can take out one or more mortgages. But a person must offer that house as security against a given mortgage. By considering the loop of associations, identify a problem with the model, and suggest a suitable constraint using OCL.

A

The model would allow one person to have a mortgage that uses someone else’s home as security. You need to capture the fact that a house’s owner is the same person who offered that house as security for a given mortgage. When there are multiplicities in the loop that can be greater than one, you need to take care in writing the invariant. In one direction around the loop, an individual house has only one owner. In the opposite direction, each house is security for only one mortgage, and that mortgage is associated with only one owner. This makes it easy to place an appropriate constraint on either the House class or the Mortgage class. For the House class, we could write: context House inv:self.owner = self.mortgage.person.Similarly, for the Mortgage class, we could write: context House inv:self.person = self.security.owner. However, expressing an equivalent constraint on the class Person is more problematic because you would have to find the intersection of two sets: the dwellings owned by a particular person and the mortgages taken out by the same person. We suggest that you use English to formulate a suitable constraint in such circumstances. You could place the constraint inside a note and attach it to the appropriate class.

40
Q

Suppose that thereis a class Person in a model, and you haveidentified the attributes title, firstName, lastName, sex, houseNumber, streetName, city and postcode, all of which are represented as strings. Write an appropriate invariant that will constrain the attribute values to exclude invalid values.

A

We might constrain some fields to have appropriate capitals and constrain others to
contain only values from a fixed set as follows:
{title must be spaces, or one of ‘Mr’, ‘Mrs’ or ‘Ms’; firstName and lastName are written in lower case, but upper case is applied either to the first character of a word or after a space; sex must be ‘M’ or ‘F’ or an empty string; houseNumber must contain only digits, forming a number greater than zero, optionally followed by a letter; streetName and city are written in lower case, but upper case is applied either to the first character of a word or any character after punctuation or spaces;
postcode may contain upper-case letters and digits, and a single space} The invariants are certainly all things that must remain true, but they may not be the whole truth. For example, the constraint given above is necessary for a postcode to be valid, but it is not sufficient: a string could conform to it but still not be a postcode that actually exists. However, the constraint will always be true, if the system is
implemented correctly. Unfortunately, the invariant for title is probably incorrect. There are other commonly approved titles such as ‘Dr’ and ‘Sir’.

41
Q

Figure 53 shows a fragment of a class model for a chain of video libraries. It includes an attribute called location for the class VideoLibrary to show where each branch is located. The class Member has been given two attributes: name and address. Identify a problem with theloop of associations in this model. How could an object diagram help you identify the problem?

A
The loop in the associations for the video library’s class model is similar to that for the hotel’s class model that you saw in Figure 48. That is, there are two ways of starting with a member and ending with a library. You can ask the member either which library he or she is a member of, or which library owns the stock copy that the member is borrowing. Both routes must yield the same library.
In Section 2, you saw that an object diagram is very useful for determining whether a class model is correct and sufficiently constrained, because an object diagram represents a particular configuration at a particular moment in time. For example, you could show a particular valid configuration of video library objects as in Figure 54. In another object diagram, you might (try to) show an invalid configuration. If you can show an invalid configuration, then you might want to add constraints, or change the model, to prevent it.