The specification states - you should be able to:
Explain object-oriented programming terminology: objects, classes, methods and inheritance.
Evaluate the use of the object-oriented approach.
5 (a) Explain the following object-oriented programming terms. OBJECT [3]
A self-contained component/abstract design relating to a real world object
... Which is constructed from a class/an instance of a class
It describes details of the object including
.. data/properties
and functions/methods
Is an instance of a class (3 × [1])
[CCEA 2021 Q5 a]
Object-oriented programming makes use of objects when designing and building applications.
An object is an element of a program that can perform actions and interact with other elements of the program.
When designing a program or application objects are considered first.
During the design process objects are defined formally.
Once all of the objects have been defined, the building of an application can begin.
Objects occur in the real world, for example a car could be described as an object.
The car would have certain attributes such as colour, registration number, make, model, engine size and so on.
In OOP the attributes that describe objects care called properties.
A car can perform actions for example start ignition, accelerate, brake, stop the engine. In OOP these actions are called methods.
Methods allow the objects to do things and allow the properties of the object to be manipulated.
Objects therefore describe real world elements through the use of methods and properties.
[CCEA Fact file]
5 (a) Explain the following object-oriented programming terms. CLASS [3]
A template that specifies
.. the properties...
and methods...
That relate to a real world object.
[CCEA 2021 Q5 a]
5(b) Explain how each of the following is implemented in a class in an object-oriented program. An attribute and a Behaviour. [4]
Attributes:
These are defined as variables/constants
… of the appropriate type [1] + [1]
Behaviours:
These are defined as procedures/functions/methods
… with appropriate parameters/return types [1] + [1]
[CCEA 2019 Q5 b]
A class is the basic building block of object oriented programming.
The class specifies the attributes and behaviours that relate to the real world object.
A class is a template, plan or blueprint that describes the details of an object.
An object is constructed from a class.
A simple example of the class car could be defined as having the data: Registration Number, Make, Model and Year of Manufacture.
A method associated with the class could be to calculate the age of the car on 1st January.
Note that a class is only a definition of objects of the same kind. It is an abstract design.
That becomes real when Objects are constructed or instantiated from that class.
An object is a specific instance of a class that contains real values. An example of an object for this class would be: DUI 78900, Ford, Fiesta, 2000.
A class is defined by its name, its data members and its member functions (e.g. methods).
A class encapsulates or hides these elements within its structure (encapsulation).
The class can be re-used within a number of applications.
Access to data is provided through member functions.
[CCEA Fact file]
5 (a) Explain the following object-oriented programming terms. METHOD [3]
A section of code/procedure..
contained within a class.
It defines an action that an object of that class can perform.
Methods only have access to data within their own class.
[CCEA 2021 Q5 a]
As already indicated, a method is a section of code or procedure contained within a class which defines an action that an object of that class can perform.
A class can have a number of methods.
The methods only have access to data within their own class.
A method is always associated with a class.
[CCEA Fact file]
5(d) Code reusability is an important aspect of object-oriented programming (OOP). Evaluate the use of inheritance in supporting code reusability. [6]
Features of inheritance
A new class can inherit the attributes and behaviours of an existing class.
Terminology: base/parent/super class derived/child sub class.
The derived class inherits all the attributes and behaviours of the base class.
New attributes and behaviours can be defined for derived classes.
Evaluation (The use of inheritance in supporting code re-usability)
Inheritance is a key part of OOP New classes are created from existing classes.
The appropriate code for attributes and behaviours is automatically re-used.
The code does not have to be written and tested.
This reduces development time.
A single base class can be used to define many sub classes.
[CCEA 2021 Q5 a]
Inheritance is a fundamental feature of OOP.
A new class can inherit the attributes and behaviours of an existing class.
In this case the new class is known as a derived, child or sub class.
The existing class is known as a base, parent or super class.
The derived class inherits all the attributes and behaviours of the base class.
The benefit of inheritance is that new attributes and behaviours can be defined for the derived class.
In addition, the base class can be re-used to define new more specialised classes.
Consider the diagram (Fig 1.). This could represent an inheritance hierarchy. The base class is Person. Both Employee and Student are derived from the base class Person. Both will have the attributes and behaviours associated with a Person. Each will have their own specialised behaviours and attributes.
[CCEA Fact file]
6 (d) It is claimed that the object-oriented approach can lead to faster software development. Evaluate this claim. [6]
The OO approach makes use of objects when designing and building applications.
An object can perform actions and interact with other objects.
Objects are defined in blueprints called classes which define their properties/attributes and methods/behaviours.
Evaluation:
The OO approach encourages code reuse.
Existing objects can be re-used in other applications
… and new objects can inherit from existing objects
… reducing the time needed to create new objects.
Reused objects will already have been tested
… reducing the time needed to be spent on testing.
[CCEA 2023 Q6 d]
The Object Oriented approach is an efficient way of developing applications for the following reasons:
Classes and methods created for one object oriented application can be reused in other programs and applications. In addition objects can be extended to include other behaviours and attributes. Re-use enables faster development and lowers the overall cost.
Encapsulation means that once an object is created, it can be used without knowledge of how it is implemented or coded. In addition, objects can hide aspects of themselves from programmers which means that certain parts of the code cannot be altered.
Due to the modular nature of OOP, designers go through an extensive planning phase. This means better designs with fewer flaws and less time spent on program maintenance.
The OO approach can also improve software quality. Firstly, a class can be tested in isolation, away from the application in which it is intended to be used. Secondly, with the use of inheritance, the testing of a derived class can assume the base class is correct and can focus on the additional attributes and behaviours.
[CCEA Fact File]
5(c) Describe two benefits of inheritance. [6]
Objects/code can be re-used.
New code is needed only for additional/modified methods/properties.
This increases productivity.
This reduces development time. (3 × [1])
The base class will already have been tested.
Only the derived class/new methods/modified methods require testing.
This improves software quality.
This reduces testing time. (3 × [1])
[CCEA 2019 Q5 c]
5(c) Discuss how the use of inheritance in the object-oriented approach should result in improved productivity in developing software. [5]
Inheritance
A new class can inherit the properties (attributes) and methods (behaviours) of an existing class and have additional properties and methods.
The existing class is the base/parent/super class.
The new class is the derived/child/sub class.
Improved productivity
A new class does not have to be developed from scratch.
The code of an existing class can be reused.
New code is required only for the additional properties and the additional/overwritten methods.
This reduces development time.
The super class will have been already tested.
Testing is required only for the additional properties and the additional/overwritten methods of the derived class.
This reduces the time required to perform testing.
[CCEA 2018 Q5 c]
Concepts including inheritance and encapsulation can be difficult to understand in the first instance meaning that there is a steep learning curve. This means that programmers must learn extensive class libraries before even beginning to program simple applications.
Object oriented programs can incur run time cost due to dynamic dispatching. This is where the process selects which particular version of a method to call (polymorphism).
[CCEA Fact File]