You are on page 1of 10

THE BCS PROFESSIONAL EXAMINATION

BCS Level 5 Diploma in IT


October 2009
EXAMINERS' REPORT
Object Oriented Programming

Section A
Answer Section A questions in Answer Book A
Question A1
a)

Compare and contrast:


i)
ii)
iii)

Structured programming;
Programming using abstract data types;
Object oriented programming.
(15 marks)

Answer pointers
Structured programming: A technique for organizing and coding computer programs in which a hierarchy
of modules is used, each having a single entry and a single exit point, and in which control is passed
downward through the structure without unconditional branches to higher levels of the structure. Three
types of control flow are used: sequential, test, and iteration.
A collection of data and a set of operations on that data is called an Abstract Data Type. The definition of
the operations must be rigorous enough to specify completely the effect that they have on the data yet the
definition must not specify how to store the data nor how to carry out the operations. This leads to data
hiding and encapsulation.
O-O programming languages take the concept of an abstract data type and makes it possible to use
ADTs as first class types in the language (i.e. variables can have a user-defined type). In addition OO
languages allow new types to be developed through an inheritance mechanism.
In structured programming control flow is the most important issue, whereas with ADTs and OO
programming data and its associated operations are the most important issue. OO approaches improve
on ADT programming by treating ADTs as types in their own right and by supplying a mechanism to reuse existing code.

(b)

Describe five advantages of the object oriented programming paradigm.


(10 marks)

Answer Pointers
Candidates might have discussed any of the following issues (or any others that are appropriate):
Faster development

Increased Quality
Easier maintenance
Enhanced modifiability
Exploit power of OOP languages
Reuse of software and designs, frameworks
Systems more change resilient, evolvable
Reduced development risks for complex systems, integration spread out
Appeals to human cognition, naturalness
Examiners Comments
This question examines part 8A of the syllabus: Foundations
The majority of candidates chose to answer this question, however, only a few obtained high marks. In
general, candidates obtained a bare pass by answering part a) of the question but scored poorly on part
b). There continues to be a confusion between Abstract Data Types and Abstract Classes and Methods.
The answers to part b) were disappointing in that candidates seem to be unable to justify the use of
object oriented programming techniques. The majority of answers simply listed features of object oriented
programming without stating what advantages they offered the programmer.

Question A2
a)

Explain the following:


i)
ii)
iii)

abstract method;
abstract class;
abstraction.
(9 marks)

Answer Pointers
i)

An abstract method is effectively a placeholder in a superclass. It defines a method that will


appear in one or more subclass definitions but does not provide code to implement the method.

ii)

An abstract class may be declared explicitly as abstract or it maybe implicitly abstract because it
contains an abstract method. It is a class which cannot be instantiated.

iii)

Abstraction is the process of generalising by reducing the amount of information in a given


situation to that relevant for fulfilling a particular purpose.

b)

How do abstract methods and abstract classes support polymorphism? Illustrate your
answer with at least one code example.
(8 marks)

Answer Pointers
An abstract superclass effectively defines all the methods that its subclasses must implement without
stating the details of that implementation. This means that the subclasses can have different ways of
implementing a method with the same name. For example, there might be a superclass called Shape. It
may make little sense to be able to instantiate Shape since we need to be more specific about the exact
shape e.g. circle or rectangle. We might, however, know that all Shapes can be drawn so we can include
draw() as an abstract method of Shape. Each subclass of Shape will implement its own version of draw().
Suppose Circle and Rectangle are subclasses of Shape. Consider the code:

Shape c = new Circle();


Shape r = new Rectangle();
Then
c.draw();
r.draw();
will invoke different versions of draw.

c)

Explain how polymorphism supports code reuse.


(8 marks)

Answer Pointers
If we have a language which supports polymorphism via inheritance, then we only have to rewrite those
parts of the behaviour which are different. For example, if the only difference between Rectangle and
Circle is that they are drawn differently, then we can put all the common code into Shape and simply
implement draw() in both classes. Code which is common to both classes is only written once and only
methods which express behaviour which varies need to be written separately. In this way the majority of
code is reused.
Examiners Comments
This question examines part 8B of the syllabus: Concepts
Again this was a popular question in which candidates gained bare passes by answering the earlier parts.
The later parts of the question were less well answered. Answers to part a) generally provided correct
definitions of abstract method and abstract class but many candidates were unable to define abstraction.
Pat b) was less well answered and only a few candidates were able to provide convincing code
examples. In part c) candidates were able to define polymorphism and code reuse but seemed unable to
connect the two ideas.

Question A3
a)

Explain the following terms:


i)
ii)

object;
class.
(6 marks)

Answer Pointers
An object combines data elements with operations on those elements. In many cases the data
may only be manipulated via the associated operations.
A class is used to define the data elements and operations that an object possesses. Object are
created by instantiating a class.
b)

Using code examples describe the following three types of inter-class relationship:
i)

inheritance;

ii)
iii)

association;
aggregation.
(9 marks)

Answer Pointers
Inheritance is a way to form new classes using classes that have already been defined. The new classes,
known as derived classes, take on (or inherit) attributes and behaviour of the pre-existing classes, which
are referred to as base classes or super classes. It is intended to help reuse existing code with little or no
modification.
class mySuperClass{
}
class mySubClass extends mySuperClass{
}
Association defines a relationship between classes of objects which allows an object instance to cause
another to perform an action on its behalf. This relationship is structural, because it specifies that objects
of one kind are connected to objects of another.
class Class1{
Class2 c;
}
class Class2{
Class1 c;
}
Aggregation is a special type of association typified by the situation where an object consists of a number
of sub-parts. Sub-parts have an existence independent of the main part but may only be sub-parts of a
single part.
class Class2{
}
class Class1{
Class2[] c;
}

c)

Use a code example to describe what is meant by delegation and explain the benefits of this
technique.
(10 marks)

Answer Pointers
Delegation is the concept of handing a task over to another object. In object-oriented programming it is
used to describe the situation where one object defers a task to another object, known as the delegate.
class Delegate {
void method1() { System.out.println("Delegate doing method1()"); }
void method2() { System.out.println("Delegate doing method2()"); }
}
class MyClass {

// delegation
Delegate delegate = new Delegate();
void method1() { delegate.method1(); }
void method2() { delegate.method2(); }
}
public class Main {
public static void main(String[] args) {
MyClass x = new MyClass();
x.method1();
x.method2();
}
This approach comes in useful where MyClass is supplied as a class which may not be altered but we
wish to tailor its behaviour for a particular situation. Class Delegate can be written to accommodate the
particular concerns of the context and the overall behaviour of the program will modify accordingly.
Examiners Comments
This question examines part 8B of the syllabus: Concepts
This question was only attempted by a third of the candidates. The average mark was quite low because
very few of the candidates supplied adequate solutions to parts b) and c) of the question. A number of
candidates chose to answer part b) by producing UML diagrams which represent inheritance, association
and aggregation. The question clearly asked for code examples and consequently these answers were
not given any credit. It was clear from the answers given to part c) that most candidates did not
understand the term delegation in the context of object oriented programming.
Section B
Answer Section B questions in Answer Book B
Question B4
a)

In the context of a design pattern, explain what is meant by the following: motivation,
prerequisites, structure, participants and consequences.
(10 marks)

Answer Pointers
When defining a design pattern, the following should be covered as part of the documentation:
Motivation scenario consisting of a problem and a context in which this pattern can be used.
Prerequisites what needs to be in place beforehand.
Structure graphical representation of the pattern. Class diagrams and Interaction diagrams may
be used for this purpose.
Participants listing of the classes and objects used in the pattern and their roles in the design.
Consequences description of the results, side effects, and trade offs caused by using the
pattern.
b)

Give an example of three different types of design patterns, explaining what type of problems they
aim to resolve, include an example of their use.
(15 marks)

Answer Pointers
Three design patterns are required, which could include the following. A short description is required for
each one, which should include a simple example and an explanation of when it should be used.
Adapter
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
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
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
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
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.
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.
Examiners Comments
This question examines parts 8c & 8d of the syllabus Design and Practice
This question was attempted by a third of the candidates. For Part A. a lot of answers gave a general
description of what a design pattern was, but did not always describe them in the context of motivation,
prerequisites, structure, participants and consequences, so lost marks. Higher marks were given to
answers that covered these areas.
Part B was generally answered adequately, most candidates could give a general description of three
design patterns, but did not always state what they aimed to resolve, or include any example of their use,
which was needed to gain full marks.

Question B5
The Very Large Programming Conference (VLPC) is an annual international conference that is held every
September in a different country. Each year a call for papers invites academics to write papers for the
conference. Authors write their papers and submit them to the conference for reviewing. The conference
has a Programme Chair who appoints the reviewers, who are called the Programme Committee. A subset
of this Committee are chosen to be Regional Chairs. After the closing date for submissions, the Regional
Chairs assign each paper from their region a unique number and then send it out to two reviewers. Each
reviewer will review their allocated papers, by providing a score fore each paper and comments for the
author(s).
The Regional Chair will collate the reviewers comments and will produce a list of papers, ordered by their
score, which will be sent to the Programme Chair. The Programme Chair makes the final decision on the
papers. Those with high scores will be accepted for the conference, whereas papers with a low score will
be rejected outright. Depending on the reviewers comments, a further decision will be made as to
whether a paper needs to be revised by the authors; or can be accepted for the conference without
changes. If a paper needs revisions, the authors have to resubmit a new version within a months
deadline. When the required number of papers have been accepted for the conference, the Programme
Chair will produce a Conference Programme.
a)

Draw a use case diagram for this system


(15 marks)

Answer Pointers

b)

Discuss how Use Case diagrams and descriptions provide an overview of the user requirements
of a system. Within your answer include examples from the above system.
(10 marks)

Answer Pointers
The candidate should discuss where Use Cases should be used in developing a system.
As part of the development process, the designer should develop a set of scenarios for each Use Case
on the Use Case Diagram. 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 candidate should include a brief example of a scenario to illustrate their points.
Examiners Comments
This question examines parts 8c of the syllabus Design
This proved to be a popular question and was generally answered well. Most candidates produced a
good Use Case diagram for Part A, identifying the main Use Cases and Actors. Marks were lost if the Use

Case was not connected to the correct Actor, or had inappropriate extend or include relationships.
Lower marks were given where the Use Cases were not correctly identified, or wordy descriptions of all
the actions were included.
A number of candidates did not answer Part B correctly, giving lengthy Use Case descriptions, which may
have been more appropriate to a previous exam paper. Some answers just described the diagram from
Part A, so again gained little credit. To gain a high mark, the answer should discuss how Use Cases are
used to develop a system.
Question B6

Given the following Class diagram:


Staff
-staffNo : int
-name : string
-address : string
-salary : float

Department
-worksFor

1..*

-employs

#departmentNo : int
#departmentName : string
+noOfDepartments : int

Sales Person
-commission : float

a)

Using an object-oriented language that you are familiar with, write code to produce the following:
a. Class definitions for all classes
(10 marks)
b. A constructor for Department, with 2 parameters for departmentNo and
departmentName. noOfDepartments should be incremented each time a Department is
created. Show how this constructor can be used in practice.
(6 marks)

Answer Pointers
Sample Java code:
public class Department{
protected int departmentNo;
protected String departmentName;
public static int noOfDepartments = 0;
public Department (int deptno, String dname) {
departmentNo = deptno;
departmentName = dname;
noOfDepartments ++;
}
}
abstract class Staff{
private int StaffNo;

private String name;


private String address;
private float salary;
private Department worksFor;
}
class SalesPerson extends Staff {
private float commission;
}
public class DeptTest {
Department d1 = new Department(10,"Test");

}
b)

Discuss how the above object-oriented code can be tested.


(9 marks)

Answer Pointers
An open-ended question. The candidate may look at different approaches, for example:
- Fault based testing
- Scenario based testing
Or may discuss black-box and white-box testing with respect to OO programming.
Examiners Comments
This question examines parts 8d of the syllabus Practice
This proved to be a popular question and Part A was generally answered well. Most candidates could
provide the basic class definitions and the constructor. Exact syntax was not required, though some
candidates gave very sketchy class definitions and did not include any data types. Other marks were lost
by not defining the class variable, abstract class or the instantiation of the class. The candidates who
obtained high marks demonstrated evidence of having practical experience of object-oriented
programming, such as C++, Java or a .NET language.
A lot of candidates described white and black box testing in Part B, but lost marks by not saying how
these could be used in the context of object-oriented programming. Some candidates lost marks by
describing how to debug code, rather than test it.

You might also like