Three things that define an object
fields, methods, identifiers
Class
Defines methods and attribute fields that capture the common behaviours and characteristics of objects
Object
Instance of a class
Constructor
Method used to instantiate an object and initialise its attributes
Instantiation
Process of creating an object from a class
Encapsulation
Concept of keeping an object’s data (attributes) and code (methods) within the same unit which is the actual object
Inheritance
Concept where the sub-class can use all attributes and methods from the parent class
Polymorphism
Concept related to inheritance, where a method in the parent class may be redefined to meet the requirements of the sub-class; its identifiers will remain the same
Overriding
Concept linked to polymorphism, in which the redefined method takes precedence over the method with the same name in the parent class
Accessors
Method that allows other objects to obtain the value of instance variables or static variables (getter methods)
Mutators
A method used to control changes to a variable (setter methods)
Association
A relationship between two classes. There are different types of association: composition and aggregation.
Algorithm
A sequence of steps to complete a task that always terminates
Aggregation
A type of association where the aggregated object has a weaker form of association with the objects that it is aggregating than is the case with composition. These objects have an existence independent of the aggregated object and can continue to exist even after the aggregated object is disposed of.
Composition
Forming one larger object from multiple smaller objects, where the smaller objects can’t exist separately from the larger object
Abstraction
The actual method is not supplied in the parent class which means it must be provided in the sub-class. In this case, the object is being used as an interface between the method and the data
Static method
Method that can be used without an object of the class being instantiated
Virtual
A method is defined in the parent class but can be overridden by the method in the sub-class where it will be used. This is a feature of polymorphism
Why is OOP used?
encapsulation, reusability of methods, easier debugging, less error-prone, programmers don’t need to know how the code works, data integrity
Association by aggregation
Concept where one or more attributes inside an object are objects themselves, of other classes; if the container object is destroyed then the contained objects continue to exist
Association by composition
Concept where one or more attributes inside an object are objects themselves, of other classes; if the container object is destroyed, then the contained objects are destroyed
OOP Principle of Design: Encapsulate what varies
Creates as many classes as needed by data/problem
OOP Principle of Design: Favour composition over inheritance
Association is less error prone than inheritance, and enables easier maintenance
OOP Principle of Design: Program to interfaces not implementation
In OOP and interface = methods to be used; when a class is created that adheres to the methods in the interface; when an object is instantiated, it uses this interface because it will use the methods
Recursive techniques
A routine that calls itself for all inputs other than the base case, eventually terminates
Base case
Used to stop the recursion process. When the base case is met the recursion stops and the stack begins to unwind
What is stored in the stack frame at every subroutine call
Values of all local variables, parameters and return address
What is stored in the stack at every recursive call
Values of all local variables, parameters at moment of recursive call, return address