Sie sind auf Seite 1von 11

THE BCS PROFESSIONAL EXAMINATIONS

BCS Level 5 Diploma in IT


October 2008
EXAMINERS REPORT
Object Oriented Programming
General Comments
The scripts submitted for this paper were disappointing in quality. The only area in which candidates showed
significant ability was in Question Four where the Use Case diagrams were generally good.
In the past papers for this syllabus have made extensive use of questions which presented lists of terms and
asked candidates to define the terms. This paper made less use of this type of question, however, it was still
possible for a candidate with a good grasp of the meaning of the terms used in the syllabus to gain a pass
mark. Candidates did not appear to be able to provide these definitions given a context in which they could
be applied.
To gain more than just a bare pass in the Object Oriented Programming paper candidates need to know
more than just the definition of terms. They need to be able to reflect on why the concepts represented by
these terms contribute to the development of reliable software. This level of reflection was absent in many of
the answers.
Questions which required candidates to produce examples of code featured in this paper and have featured
in previous papers. The questions in this paper which required code were often poorly answered. It must be
recognised that, whilst the paper does not assess the ability to program, candidates who have practical
experience of using all the concepts listed in the syllabus in practice will be better equipped to perform well
in this examination.

Question 1
a)

You are working for a company which has decided to develop software using an object oriented
approach but has yet to standardise on a given langauge. Your manager has discovered that some
object oriented languages such as Java or C# implement static typing while other languages such as
Smalltalk or Ruby implement dynamic typing.

Write a report which outlines the advantages and disadvantages of static and dynamic typing.
(8 marks)
Answer Pointers
In statically typed languages the type of a variable is declared before it is used. The compiler will signal an
error if the programmer tries to assign a value which does not conform to the declared type to the variable. In
dynamically typed languages the type of a variable is determined by the type of the value assigned to it. The
advantage of static typing is that it is able to identify some semantic errors at compile time. With dynamic
typing this class of semantic error is only detected when the program is run. Static typing on the other hand
involves a large amount of syntactic overhead and it is generally argued that dynamic typing leads to shorter
development times. The problem with dynamic typing is that unless the programmer's testing is very
comprehensive then errors which would be detected by statically typed languages may manifest themselves
when the program is in use.
b)

After reading the report your manager asks you to differentiate between the concepts class and type.
Write a further report that achieves this.
(8 marks)

Answer Pointers
Whilst all object oriented languages support the concept of class, not all support types. In some object
oriented languages types which do not have corresponding classes are supported. In languages where
types are supported the type of a variable will indicate the way in which values for that variable are stored
and identify a number of built-in operations which are applicable to that variable. In an object oriented
language a class definition will indicate how the object has been constructed from simpler objects and
declare a set of operations which may be applied to objects of that class. Just as a type may be used to
signal where an operation may not be applied to a variable so a class definition can be used to identify
where an attempt to invoke a method is inappropriate because an object does not implement that method.
The use of classes is a more generic way of indicating the storage requirements and capabilities of an object
than the use of type.
c)

Inheritance permits the creation of objects which belong to one class but conform to more than one
type. Explain this statement.
(9 marks)

Answer Pointers
When a class X is used to create an object, that object holds all the data and supports the methods specified
by class X. If, however, class X is a subtype of another class then the object will also store the data and
support the methods of the supertype classes. The Liskov substitution principle states that if S is a subtype
of T, then objects of type T in a program may be replaced with objects of type S without altering any of the
desirable properties of that program. That is if an object is an object of class S and S is a subtype of class T
then the object conforms to both type T and type S.
Examiner's Comments
(This question examines part 8a of the syllabus Foundations)
This question was the least popular on the paper and in general candidates who did answer the question
performed very poorly. The basis of the question, the comparison between the concept of type and the
concept of class, has been tested in previous papers. In particular, part c has appeared in almost an identical
form on a number of occasions. In this paper, the question was phrased in a way that gave it a more
practical slant, nevertheless, candidates who had worked through previous papers and their answers should
have been fully prepared. Candidates taking this paper would benefit from exposure to more than one object
oriented language especially if one language is statically typed (e.g. Java) whilst the other supports dynamic
typing (e.g. Smalltalk).

Question 2
a)

In languages such as C which do not support objects, programmers commonly call subroutines to
allocate memory for data storage and then manipulate this data via pointers. Explain the equivalent
mechanisms in object oriented programming languages.
(8 marks)

Answer Pointers
In an object oriented language a class acts as an 'object factory'. Objects are created by applying an
operator (commonly new) to a class. At this point storage is allocated for the object and where indicated in
the class definition variables in the object are initialised with values. The result of object creation will be an
object reference which can be used to send messages to the object. The object reference is similar to the
pointer obtained when allocation memory in C.
b)

Object oriented languages contain mechanisms to initialise automatically memory when it is


allocated. Use code examples to show how these mechanisms are used and show how they operate
for objects that are instances of a subclass.
(8 marks)

Answer Pointers
Values of components of an object can be set using a constructor.

class MyClass{
private int myValue;
public MyClass (int v){
myValue = v;
}
}
MyClass mc = new MyClass(3);
mc is set to reference an object of MyClass where myValue is 3.

class MySuperclass{
private int superValue;
public MySuperclass (int v){
superValue = v;
}
}
class MySubclass extends MySuperclass{
private int subValue;
public MySubclass(int v1, int v2){
super(v1);
subValue = v2;
}
}
MySubclass ms = new MySubclass(1, 2);
Creates an instance of MySubclass with superValue set to 1 and subValue set to 2.Values of components of
an object can be set using a constructor.

class MyClass{

private int myValue;


public MyClass (int v){
myValue = v;
}
}
MyClass mc = new MyClass(3);
mc is set to reference an object of MyClass where myValue is 3.
class MySuperclass{
private int superValue;
public MySuperclass (int v){
superValue = v;
}
}
class MySubclass extends MySuperclass{
private int subValue;
public MySubclass(int v1, int v2){
super(v1);
subValue = v2;
}
}
MySubclass ms = new MySubclass(1, 2);
Creates an instance of MySubclass with superValue set to 1 and subValue set to 2.

c)

Where programs acquire memory dynamically it is important that there is a mechanism for releasing
memory when it is no longer required. Compare and contrast two such mechanisms used in object
oriented programming languages.
(9 marks)

Answer Pointers
Some object oriented languages release memory via a garbage collection mechanism. Here the memory an
object occupies may be released when there are no references to the object. Memory release does not
automatically occur at the point the last reference to the object is deleted, at certain times the garbage
collector inspects memory to see if memory may be released. This inspection may be postponed to the point
where the available memory falls below a predefined limit. Other languages implement explicit destructors
which may be invoked by a programmer when an object is no longer needed. There is a processing
overhead imposed by the garbage collection mechanism, however it ensures that an object's memory is not
reallocated until that object is no longer required. The destructor approach requires that programmers are
able to identify objects which may have their memory reused, if they incorrectly deallocate memory then the
program will fail.
Examiner's Comments
(This question examines part 8b of the syllabus Concepts)
This question was similar to questions and memory management which have appeared in previous papers
and perhaps due to this attracted a large number of answers. Some candidates were awarded a full 25
marks for their answers whilst other candidates did very poorly. The question required candidates to
understand the mechanisms that underpin the declaration of an object reference and th allocation of
dynamic memory in an object oriented language. In general, part a) received adequate answers. The
answers to part b) were disappointing with candidates failing to produce code examples which have featured
in many recent examination papers on this syllabus. In part c) candidates were able to cite the two memory

management mechanisms but were unable to compare and contras them.

Question 3
a)

Give the meaning of the following terms:


i) Abstraction;
ii) Encapsulation;
iii) Data hiding.
(9 marks)

Answer Pointers
i)
the identification of common features and operations;
ii)

the process of combining elements to form an new entity;

iii)

a mechanism for hiding the details of the implementation of an object from the code that uses it.

b)

A programmer wishes to create a set of classes that implement collections (e.g. Set, SortedSet, List,
SortedList). Explain how abstraction, encapsulation and data hiding can be used to create generic
classes for this purpose.
(10 marks)

Answer Pointers
A process of abstraction should tell us that all collection classes do essentially the same task. In particular
every collection class will be able to add to the collection and remove items from the collection. Via
polymorphism the nature of these operations may however be different so adding to a Set will be
implemented in a different way from adding to a List (duplicates are allowed in lists but not in sets). Data
hiding will conceal these differences from us so that we neednt worry about them but just be aware that
adding may in some cases fail. Encapsulation will allow us to package different parts of an entity together as
an object. Collection classes which will operate on objects can be used in any context so that it is not
necessary to implement a specialist class for each different type of object we wish to collect together.

c)

Describe the contribution that abstraction, encapsulation and data hiding make to the potential of a
language to encourage software reuse.
(6 marks)
Answer Pointers
By identifying the most general cases and hiding the details of specific implementations from the code using
it, it is possible to develop set of classes which operate on all objects rather than just objects belonging to
specific classes. Such classes are easily reusable.
Examiner's Comments
(This question examines part 8b of the syllabus Concepts)
This question was answered by the majority of candidates. Most candidates were able to give good answers
to part a), although the design principle of abstraction was sometimes confused with the use of abstract
classes. Candidates were less able to give satisfactory answers to parts b) and c) of the question. In part b)
it was clear that many candidates are unfamiliar with the use of collection classes, although these are clearly
listed in the syllabus. The answer to part c) followed naturally from the reflection required for part b) and
therefore many attempts at part c) were unable to provide a concrete argument for the contribution of
abstraction, encapsulation and data hiding to software reuse.

Question 4
PC Wide is a store selling computers and related goods, who employs a number of sales assistants. Each
sales assistant works at an electronic till. The first thing a sales assistant does when they start work, is to
login into the sales system, to which all tills are connected. Logging in identifies them to the system. If the
sales assistant has finished work, or needs to leave the till for any reason, he/she must log off the till. Only
registered users can logon to a till. The Store Manager registers the sales assistants with the system. The
Store Manager can also remove the users from the system if they leave.
When a customer wishes to purchase an item, they will approach a sales assistant, who receives payment
from the customer, which can be either cash or credit card. The details of the payment are entered into the
till, which records that the item has been purchased. For expensive items, such as a laptop, the system will
optionally offer the customer insurance on the item, which they can either accept or reject. At the end of the
transaction a receipt is printed.
If the customer is unhappy with the purchase, they can return it to the shop within 15 days. The customer will
take the purchase to a sales assistant who will refund their money and records the return of the item via the
till.
Every week the Store Manager generates a sales report, which shows what items have been sold that week.
a)

Draw a use case diagram for this system


(15 marks)

Answer Pointers

For full marks each Use Case should be linked to the correct Actor and the system boundary defined.
b)

Discuss how Use Case diagrams and scenarios contribute to the development of the usage
requirements of a system. Within your answer include examples from the above scenario.
(10 marks)
Answer Pointers
The candidate should discuss where Use Cases should be used in developing a system. For each Use Case
on the Use Case Diagram the user should develop a set of scenarios. Scenarios are natural language
descriptions of an instantiation of the Use Case.
These can be used in the following areas:
- Initial investigation
- For identifying what functionality is required from the system
- The descriptions give the fuller detail
- Testing purposes
The Use Case descriptions can be used by the testers to develop test plans, checking that the system meets
the requirements of the system
The candidate should include a brief example of a scenario to illustrate their points, e.g., Register Returns.

Examiner's Comments
(This question examines parts 8c of the syllabus Design)
This question was answered by the majority of candidates. Part a) involved drawing a use case diagram for
the PC Wide system. In general, this part was well answered and candidates obtained good marks for this
section, identifying the main actors and use cases. Marks were lost if some of the use cases were missing;
were not connect to the correct actors or the Extends/Uses relationships were missing or inappropriately
connected. Lower marks were given to candidates who could not distinguish the use cases, instead
including all the actions, which led to a much cluttered diagram.
For this question, most marks were lost in part B, where candidates neglected to discuss how use cases
diagrams and scenarios contributed to the development of the usage requirements of a system. Some
candidates just provided use case descriptions only without tailoring it to the question, e.g., to give an
example of providing fuller details of the requirements.
Question 5
a)

Explain what is meant by the term design pattern in the context of object oriented programming?
Within your discussion, highlight what is the motivation for using design patterns from a
programmers point of view.
(10 marks)
Answer Pointers
Design patterns can be used in all sorts of different areas (original patterns from architectural background).
In software engineering terms a pattern is a named problem/solution pair that can be applied in new contexts
with advice on how to apply it in novel solutions. Basically general principles and idioms codified in a
structured format.
For a programmer design patterns are devices that allow programs to share knowledge about their design. A
programmer can encounter many problems that occur again and again and they often have to ask
themselves is how we are going to solve it this time. Documenting patterns can lead to reuse, possibly
allowing the information to be shared with other programmers about how it is best to solve a specific
program design problem.
b)

Design patterns can be classified according to the problem they solve. For example:
Creational Patterns:
Abstract factory, Builder, Object Pool and Singleton patterns
Structural Patterns:
Adaptor, Decorator, Faade and Proxy patterns
Behavioural Patterns:
Command, Iterator, Observer and State patterns
Pick ONE design pattern from EACH of the above classifications and give a detailed
description of each, stating the problem they address and the basis of the solution they offer.
(15 marks)

Answer Pointers
The following five are listed design patterns from the syllabus.
Adapter (Structural)
The Adapter is intended to provide a way for a client to use an object whose interface is different from the
one expected by the client, without having to modify either. This pattern is suitable for solving issues such as
replacing one class with another when the interfaces do not match and creating a class that can interact with
other classes without knowing their interfaces at design time.
Decorator (Structural)
Ordinarily, an object inherits behaviour from its subclasses. The decorator pattern allows the behaviour of an
object to be extended and dynamically compose an object's behaviour. Decorator allows this without the
need to create new subclasses.
Iterator (Behavioural)
The Iterator pattern provides a way to access the elements of an aggregate object sequentially without
having to know the underlying representation. Iterator also provides a way to define special Iterator classes
that perform unique processing and return only specific elements of the data collection. The Iterator is useful
because it provides a common interface so programmer does not need to know anything about the underling
data structure.

Observer (Behavioural)
The Observer pattern is useful when data is to be presented in several different forms at once. The Observer
is intended to provide a means to define a one-to-many dependency between objects so that when one
object changes state, all its dependents are notified and updated automatically. The object containing the
data is separated from the objects that display the data and the display objects observe changes in that data.
Often used in MVC.
Singleton (Creational)
The singleton pattern applies to the many situations in which there needs to be a single instance of a class,
a single object. Print spoolers and window managers are examples of Singletons. The Singleton is intended
to provide a way to ensure that a class provides one instance of itself, and to provide a global point of
access.
The others are:
Creational
Abstract factory
Provides an interface for creating families of related or dependent objects without specifying their concrete
classes
Object Pool
Manages the reuse of objects for a type of object that is expensive to create or only a limited number of a
kind of object can be created.
Structural Patterns:
Faade
The Faade pattern simplifies access to a related set of objects by providing one object that all objects
outside the set use to communicate with the set.
Proxy
The Proxy pattern forces method calls to an object to occur indirectly through a proxy object that acts as a
surrogate for the other object, delegating method calls to that object. Classes for proxy objects are declared
in a way that usually eliminates client objects awareness that they are dealing with a proxy. Proxy is a very
general pattern that occurs in many other patterns, but never by itself in its pure form.
Behavioural Patterns:
Command
Encapsulate commands in objects so that you can control their selection, sequencing, queue them, undo
them and otherwise manipulate them.
State
Encapsulate the states of an object as discrete objects, each belonging to a separate subclass of an abstract
state class.
For each category, the candidate should give a short description of one of the diagrams, include a simple
example and say when they should be used
Examiner's Comments
(This question examines part 8c of the syllabus Design)
This question proved less popular with candidates. Part A was generally answered adequately and
candidates could describe what a design pattern was with respect to object oriented programming. Higher
marks were given to answers that went into details of the motivation of using a design pattern.
In part B some candidates lost marks by including two design patterns from the same category. The
singleton, adaptor and observer proved to be the most popular design patterns. Most answers could
describe what the design pattern did, but then lost marks by not addressing the problem they solved or what
solution they offered.

Question 6
The class diagram below represents a Banking system that records what type of customers they have and
their accounts.

a)

Describe what the diagram above represents. Include all structural constraints.

(15 marks)
Answer Pointers
The diagram has the following classes:
Branch
Customer
Employee
Employee has a subclass Business Manager
Customer is an abstract class and has two subclasses, Business and Personal
Branch has the instance variables branchNumber, name, address and telephone number.
Employee has the instance variables employeeNumber, name, address, extensionNumber, salary and a
static variable numberOfCustomers
Business Manager has the instance variable commission
Customer has the instance variables customerNumber, name, address and telephoneNumber
BusinessCustomer has the instance variables faxNumber and annual Turnover
PersonalCustomer has the instance variables emailAddress and mobileNumber
There is also an association class, Account, between Branch and Customer, which has the instance
variables accountNumber, type, balance and overdraftLimit.
The cardinality of the associations are:
- Branch and Employee is 1:M
- Business Manager and Business Customer is M:N
- Account is 1:M

b)

Explain why the object diagrams below (i-ii) are not legitimate instances. Say how they can be made
legitimate.
(5 marks)

i)

ii)

Answer Pointers
Diagrams are incorrect because:
(i)
Many Branches linked to one Business Manager, either should show it as a 1:1 relationship, or
many Business Managers to one branch.
(ii)
Should be no link between a Business Manager and a Personal customer. Either should be no
links at all, or a link between a Business Manager and objects of type Business Customer.
c)

What is the purpose of an activity diagram? Describe how they might help in the development of the
Banking system.
(5 marks)
Answer Pointers
Purpose of Activity Diagrams:

to model a task (for example in business modelling)

to describe a function of a system represented by a use case

to describe the logic of an operation

to model the activities that make up the life cycle in the Unified Process
Any of these are appropriate to help build the Bank system.
Examiner's Comments
(This question examines part 8c of the syllabus Practice)
This question was answered by the majority of candidates. Parts A and B were generally well answered;
most candidates could identify the classes and the attributes. Marks were lost for: incorrectly describing the
cardinality of the relationships; not mentioning the class variable, abstract class or omitting the inheritance.
In part B, most candidates could explain what was wrong with the diagrams, but marks were lost when they
failed to explain how the diagrams could be made legitimate.
Part C often was not answered or the answer failed to describe how an activity diagram could help in the
development of the Banking system. Some answers included an example of an activity diagram, which was
not needed unless it was used to backup a point made.

Das könnte Ihnen auch gefallen