OOP questions Flashcards
Advantages of OOP
- Can modify and maintain existing code more easily.
- Reuse of code in other programs through libraries
- Clear modular structure with a defined interface -> can abstract and hide away details.
Advantages of Constants
- They have meaningful identifiers which make code easier to follow and maintain
- Constants only have to be updated in one place if the value changes.
“Inherits” meaning
The child class gains all of the non-private methods of the parent and all of the attributes of the parent.
What is Aggregation Association?
- Weaker association
- The child class cannot exist independently of the parent class
- Real-life example: A person in a car
What is Composition association?
- Stronger association
- The child class cannot exist independently of the parent class.
- Real-life example: A wheel of a car
What is encapsulation?
- Used to hide data and methods, which prevents them from being accessed and changed.
- Distinguishes attributes/methods as public, protected and private.
What is a public method / attribute ?
A method/attribute accessible from outside the class.
What is a private method/attribute?
Private methods/attribute are accessible in their own class
How can you access private attributes?
Using a defined method, e.g. GetSymbol()
What are protected methods / attributes?
Only current class can access methods / attributes.
What programming language doesn’t recognise protected attributes / methods?
Python!
How can you update private attributes?
Using a setter method.
E.g. ChangeSymbolInCell()
What is Overriding?
When a method in a child class overrides a method or attribute in a parent class.
What is Polymorphism?
Allows us to have a function that can take on many forms of its parameters by using overriding.
E.g. the built in function len ()
What is a static attribute?
Static attributes are defined for the class and can be accessed without creating an object instance.