Compare local scope and global scope.
- Local scope if it is only accessible from the structure within which it is declared.
- Global scope if it is accessible from all parts of the program.
Define the structured approach to program design.
- Only three program structures are used: sequence, selection and iteration
- Designed from the top down
- Modular
Explain what is meant by top down design.
Problem decomposition: a large task is broken down into smaller subtasks until each subtask accomplishes one identifiable task.
State 4 advantages of modular structured programming.
- Large programs can be split in modules that are easier to read, debug and maintain.
- Several modules can be worked on at the same time.
- Modules can be reused in other programs.
- Each module can be individually tested.
State 2 limitations of a hierarchy chart.
- Detailed program structures are not shown.
- Selection and iteration not specified.
Define class in OOP.
A blueprint for an object: specifying the attributes and methods which capture common characteristics and behaviours.
Define object in OOP.
An abstract data type and one instance of a class.
Define instantiation in OOP.
Creating an object based on a class, using a constructor method.
Define state of an Object in OOP.
The current values of one instance of a class' attributes.
Define encapsulation in OOP.
All of an objects methods, procedures and data are wrapped into a single entity.
Explain the purpose for encapsulation in OOP.
It uses the concept of information hiding, so that many developers may interact with an object as an abstract data type written by others without knowing how its methods are implemented.
Define inheritance in OOP.
Subclasses may share all the attributes and methods of the superclass, and then extend it with new attributes and methods.
Explain the difference between polymorphism and overriding.
- Polymorphism describes the ability to process objects differently based on their class.
- Overriding describes defining a method within a subclass with the same identifier as method in the superclass, but changing its implementation.
- Polymorphism is achieved through overriding.
Compare how you would identify the difference between a inheritance relationship and an associative relationship in OOP.
- Inheritance: x "is a" type of y
- Association: x "has a" y
State the two forms of association in OOP.
Aggregation, Composition.
Define Aggregation in OOP.
If the container object is destroyed, the constituent objects still exist independently.
Define Composition in OOP.
If the container object is destroyed, then the constituent objects are also destroyed.
State the three principles of good OOP design.
- Favour composition over inheritance.
- Encapsulate what varies.
- Program to interfaces not implementation.
Explain why you should favour composition over inheritance in OOP.
- Constituent objects may not need all the methods and attributes of its parent object.
- Composition results in a more flexible relationship.
Explain why you should always encapsulate what varies in OOP.
Reduce maintenance and testing difficulty.
Explain the concept of programming to interfaces not implementations.
Methods and procedures should be called based on how a third party would like to interact with the abstract data type, not how the abstract data type would carry out its objectives.
A driver and a car have associative relationship in an OOP program, draw a class diagram to show this relationship.
Aggregation - weaker association - white diamond on the container object.
A wheel and a car have associative relationship in an OOP program, draw a class diagram to show this relationship.
Composition - stronger association - black diamond on the container object.
State the three forms of access modifiers as used by both methods and attributes of an object in OOP.
- Public.
- Private.
- Protected.
Define a public method in OOP.
Can be accessed by methods within the defining class, via inheritance and via reference to object of a class (identifier for an instance).
Define a private method in OOP.
Can only be accessed by methods within the defining class.
Define a protected method in OOP.
Can be accessed by methods within the defining class, via inheritance and only if it is in a subclass definition.
State the three respective symbols used to represent public, private and protected methods within a class diagram within OOP.
- public = +
- private = -
- protected = #
State 3 advantages of OOP design.
- Rigidly enforced modular structure: makes it easier to maintain.
- Simpler to extend and adapt programs using composition and inheritance.
- Code can be reused in other programs without the other knowing how it works: encapsulation and modular structure.