1/10
Looks like no tags are added yet.
What is a class?
A blueprint that defines the attributes and methods that all objects of that type will have.
What is an object?
An instance of a class.
What is an attribute?
A variable that belongs to an object and stores its state
What is a method?
A subroutine that belongs to a class and defines the objects' behaviour.
What is a constructor?
A special method called when an object is created - initialises the attributes.
What is instantiation?
The process of creating an object from a class
What is encapsulation?
Encapsulation means hiding the internal data of an object from the outside world. Attributes are declared private and can only be accessed or modified through public methods (getters and setters).
What is the benefits of encapsulation?
- Protects data from invalid modification
- Hides implementation detail - the rest of the program doesnt need to know how an attribute is stored
- Makes future maintenance easier; the internal representation can change without affecting other code
What is inheritance?
This allows a subclass to be derived from an existing superclass. The subclass automatically obtains all the public/protected attributes and methods of the superclass and may add new ones or override existing ones.
Promotes code reuse and supports an "is-a" relationship (a Dog is an Animal)
What is polymorphism?
The same method can behave differently depending on the type of the object it is called on. Two main forms:
- Method overriding: a subclass provides its own version of a method already defined in the superclass.
- Method overloading: a class has more than one method of the same name with different parameter lists (not directly supported in Python or OCR pseudocode)
What are the advantages and disadvantages of OOP?
Advantages:
- Encapsulation protects data from accidental modification
- Inheritance reduces code duplication and allows reuse
- Polymorphism makes code flexible and extensible
- Programs reflect real-world entities, easier to design
- Easier to maintain and extend large projects
Drawbacks:
- Steeper learning curve that procedural programming
- Can introduce more code overhead for simple problems
- Programs can use more memory and run more slowly
- Poor design (deep inheritance) leads to brittle code
- Not all problems map naturally to objects