4.1 - Fundamentals of programming Flashcards
What is encapsulation?
A concept within OOP that all attributes and methods are linked together and contained within a class, this means the attributes are private and can’t be modified externally. Getters and setters are used to access and change data.
what is:
class Dastan: def \_\_init\_\_(self, R, C, NoOfPieces): self._Board = []
and the displayBoard method an example of
Encapsulation
What are the access modifiers and what are they used for?
They are used to determine how accessible different attributes and methods are. Protected members can be used within a parent class and subclasses. Private members can be used only within the parent class. Public members can be accessed anywhere in the code, this is useful for methods such as getters and setters, however shouldn’t be used for attributes.
What is inheritance?
Inheritance is when a subclass inherits properties from the parent class. Methods and attributes can be inherited and modified from the subclass.
What is polymorphism?
The properties of methods can be changed for individual subclasses to better fit those classes. Depending on which class the method is called on, the method can take different parameters.
What is association?
This defines the relationship between two separate classes.
What is the difference between aggregation and composition?
Aggregation - The parent object can exist without the child object and vice versa
Composition - If the parent object is destroyed so is the child object