August 1997
OP216: OBJECT ORIENTED PROGRAMMING

QUESTION 5

Total Marks: 20 Marks

Click here to access other questions

SUGGESTED SOLUTIONS
Solutions and allocated marks are indicated in green.
Return to Question 5

5. (a) Discuss any three benefits of object-oriented programming and give appropriate examples to illustrate the benefits. [12]
You should structure your answer as follows: list each benefit, discuss that benefit in more detail, and give an appropriate example. Do this for each of the three benefits.
The answer must cover the following aspects.
Encapsulation: grouping of essential characteristics or information hiding. A data structure along with its primitive operations can be encapsulated within a single abstraction. It is a technique for hiding information within a structure, such as the hiding of instance data within a class. For example, a stack could be implemented by a fixed length array whose publicly available functions would be push and pop. [4]
Inheritance: The property of objects by which instances of a class can have access to data and method definitions contained in a previously defined class.
Classes can be organised into a hierarchy. Thus, reducing the interdependency among software components and encouraging the development of re-useable software components. For example, a ball class can inherit from the sphere class. [4]
Polymorphism: allows the same function name or operator to be executed by arguments of a variety of types.
It is made possible by the overloading of function names in which two or more procedure bodies are known by the same name in a given context, and are disambiguated by the type and number of parameters supplied. [4]
(b) State and explain one disadvantage of object-oriented approaches to programming. [3]
Object oriented programming languages are harder to implement efficiently. [1]
This is because the compiled code needs to carry out more checks at runtime than normal imperative languages, like Pascal. [1]
Consequently, the code is longer and runs slower. [1]
[3 marks]
(c) Provide concise answers to the following questions:
(i) Can a non object-oriented language be used to create and use ADTs? Explain your answer. [3]
Yes. [1]
object oriented programming is just a paradigm or a methodology [1]
An ADT can be implemented using a non OOP language by hard-coding it. [1]
(ii) Why do object-oriented languages exist? [1]
Object oriented programming languages developed as they allowed a much clearer way of representing complex systems. Consequently, they can make (certain kinds of) coding easier. [1]
(iii) Name three OOP languages. [1]
SmallTalk, Simula, Java, Objective C, ADA-95, CLOS, C++ [1]
[5 marks]