1/42
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
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
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
Encapsulating the aspects of code that are prone to change so that they can be made independently to the rest of the system
Benefits of Encapsulate What Varies
Reduces coupling between different parts of the code
Improved maintainability by isolating changes
Enhanced flexibility via easier ability to extend the system
Coupling
Degree of interdependence between software modules
OOP Principle of Design: Favour composition over inheritance
Association is less error prone than inheritance, and enables easier maintenance
Benefit of Favour Composition Over Inheritance
Composition leads to loosely coupled code, where changes in one class have minimal impact on others
Greater flexibility as you can change the behaviour of a class at runtime by swapping out components
OOP Principle of Design: Program to interfaces not implementation
The code depends on abstract interfaces rather than specific class implementations. This promotes flexibility, allowing different implementations to be substituted without modifying dependent code, improving maintainability and scalability.
“Program to an interface” (OOP Design)
Should write code in a way that it depends on abstract classes rather than concrete implementation
“Not to an implementation” (OOP Design)
Your code should not directly rely on specific classes or their detailed implementations, which can change or become less flexible over time
Benefits of Program to an Interface, Not to an Implementation
Flexibility: programming to interfaces means your code remains decoupled from specific implementations. Can easily swap out or replace one implementation with another
Maintainability: it’s easier to make changes to the implementation without affecting the clients of the interface
Testability: easier to create mock implementations for unit testing
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
Variable
Memory location, given an identifier and a data type, to store data at runtime
Constant
Memory location, given an identifier and a data type, to store data but can’t change at runtime
Advantages of a constant
Can be referenced anywhere in the code. Better maintenance, only need to change constant value once
Function
Section of code, given an identifier and a data type, performs a task and always returns a value
Procedure
Section of code, given an identifier, that performs a task and may return a value - if it does, it will be via a parameter
Local variable
Variable that is visible/accessible only to the current subroutine
Advantages of local variables
Easier maintenance of code and debugging; only need to look in the subroutine using the variable that throws and exception, rather than trace the whole program
Global variable
Variable that can be accessed and altered from anywhere in the program
Advantages of a structured approach to design and coding
Easier maintenance / debugging of code
Testing can be carried out by module before being combined into the overall solution
Separate teams can work on the same project, taking over parts of it, and speeding up its completion
Why are meaningful identifier names important?
Faster debugging, maintainability, collaboration, enhanced readability, reusability
Advantages of named constants
Readability, maintainability, consistency, protection against accidental changes