User interface language: English | Español

Date November 2017 Marks available 3 Reference code 17N.2.SL.TZ0.12
Level SL Paper 2 Time zone no time zone
Command term Construct Question number 12 Adapted from N/A

Question

Construct a diagram showing the relationships between the Payment, FoodItem, DrinkItem, and Item classes. You do not need to include the names of attributes or methods.

[3]
a.

By making reference to any of the classes from 12(a), describe two benefits that a programming team would gain from the use of encapsulation.

[6]
b.

The company that owns this restaurant also owns hotels, shops, and a car hire business. The programs that manage the finances of these different businesses include classes similar to the ones shown in this paper.

Explain how inheritance could be used as a tool to both improve the clarity of the design and to reduce the amount of code that needs to be written.

[4]
c.

Markscheme

Award marks as follows, up to [3 max].
Award [1] for 4 classes connected with arrows/lines.
Award [1] for “has a” label or correct arrow from Payment to FoodItem and “has a” label or correct arrow from Payment to DrinkItem (with no additional arrows).
Award [1] for “uses” label or correct arrow going from Payment to Item (with no additional arrows).

a.

Award [1] for identifying a feature, [1] for an example in the given context, and [1] for an elaboration, for two features up to [6 max].
Encapsulation places all attributes and methods that relate to a particular object/entity together;
For example, Payment class includes attributes such as the food and drink arrays and methods such as calculateBill();
This provides a clearer view/understanding of each section of the problem;
Which can lead to more efficient programming (faster, less errors etc.);

Encapsulation protects the values of the data stored within the object;
From (accidental) changes made by other classes;
For example, quantity in the FoodItem class cannot be altered through another variable called quantity in another class;
This allows programmers to select any variable names they wish/no restriction on choice of variable names;

b.

Award up to [4 max].
A generic Payment class can be created;
This would contain data/variables/methods required by all units of the company;
Each of the different operations could then inherit this class;
Adding new variables/methods that relate only to them;
Overriding the superclass methods as necessary;

Note: Allow a similar answer that deals with the different items (FoodItemDrinkItem etc.).

c.

Examiners report

[N/A]
a.
[N/A]
b.
[N/A]
c.

Syllabus sections

Option D: Object-oriented programming » D.1 Objects as a programming concept
Option D: Object-oriented programming

View options