Object-oriented languages (see appendix 5d for pseudocode style) with an understanding of classes, objects, methods, attributes, inheritance, encapsulation and polymorphism
1.2.4 Types of Programming Language
Practise exam questionsTypes of Programming Language — Note 5 of 5
Candidates need to understand object-oriented code (as specified in the pseudocode guide). They need to have an understanding of classes, objects, attributes and methods. They need to understand the difference between private and public attributes and methods. Candidates need to understand encapsulation and the use of get and set methods to access private attributes. Candidates need to understand the purpose and principles of inheritance. Candidates need to have an understanding of polymorphism and how it can be used within a program. Candidates need to be able to read, trace, amend and write code that makes use of these object-oriented techniques
Object-oriented programming (OOP) models a system as a collection of objects that combine data and the methods that act on it. You need to understand the key OOP concepts and be able to read, trace, amend and write code using OCR's object-oriented pseudocode style.
A template or blueprint that defines the attributes and methods that objects of that type will have.
An instance of a class, with its own values for the attributes.
A variable belonging to a class/object that holds its data.
A subroutine belonging to a class that defines the behaviour of an object.
A special method that runs when an object is created to set its initial attribute values. In OCR pseudocode it is a procedure called new.
Keeping an object's attributes private so they can only be accessed or changed through its public methods (getters and setters). This protects the data from accidental or invalid changes.
A subclass takes on the attributes and methods of a superclass, and can add its own. In OCR pseudocode: class Dog inherits Pet.
Objects of different classes can respond to the same method call in different ways, e.g. a subclass overriding a method of its superclass.
super.new(...) calls the superclass constructor, and objects are created with objectName = new ClassName(parameters).class Animal
private name
public procedure new(givenName)
name = givenName
endprocedure
public function getName()
return name
endfunction
public function speak()
return "..."
endfunction
endclass
class Dog inherits Animal
public procedure new(givenName)
super.new(givenName)
endprocedure
public function speak() // overrides Animal.speak (polymorphism)
return "Woof"
endfunction
endclass
myDog = new Dog("Rex")
print(myDog.getName() + " says " + myDog.speak())Ready to test yourself?
Practise 1.2.4 questions