Topic 5 of 8 · Form 6
Programming paradigms and object-oriented programming
Try–catch blocks; testing strategies: white-box, black-box, alpha, beta, acceptance; test data: normal, boundary, erroneous.
Notes for this topic 1 file, in order
Create a free account to download PDFs.
Paradigms
- Procedural (imperative): sequences of instructions and procedures (Pascal, C).
- Object-oriented (Java, Python, C++): classes and objects.
- Declarative/logic (Prolog): facts and rules; the system finds solutions.
- Functional (Haskell): functions without side effects.
- Low-level (assembly).
Object-oriented concepts
- Class: a blueprint with attributes (properties) and methods.
- Object: an instance of a class.
- Encapsulation: data and methods bundled; attributes kept private and accessed through methods (getters and setters).
- Inheritance: a subclass gains the attributes and methods of a superclass and can add its own.
- Polymorphism: methods with the same name behave differently in different classes (overriding).
- Constructor: a method that initialises a new object.
Worked example: Define a class Student with private Name and Mark, a constructor and a method to return the grade.
CLASS Student
PRIVATE Name : STRING
PRIVATE Mark : INTEGER
PUBLIC PROCEDURE NEW(n, m)
Name ← n
Mark ← m
ENDPROCEDURE
PUBLIC FUNCTION Grade() RETURNS STRING
IF Mark >= 50 THEN RETURN "Pass" ELSE RETURN "Fail" ENDIF
ENDFUNCTION
ENDCLASS
Exception handling and testing
Try–catch blocks; testing strategies: white-box, black-box, alpha, beta, acceptance; test data: normal, boundary, erroneous.
Software development
Waterfall, iterative and rapid application development (RAD) life cycles; program maintenance (corrective, adaptive, perfective).
Check yourself
- What is encapsulation?
- Give an example of inheritance.
- Distinguish between white-box and black-box testing.
Show answers
- Bundling data with the methods that act on it, and restricting direct access to the data.
- e.g. a class Car inherits from a class Vehicle, gaining its attributes and methods.
- White-box tests the internal logic and paths; black-box tests inputs against expected outputs without looking at the code.
Questions about this topic (0)
No questions about this topic yet.
Sign in or create a free account to join in.