Step by step instructions to solve a problem breaking down problems into smaller modules consisting of subroutines
Instead of having attributes they would have variables and parameters
Attributes:
Variables contained within and associated to an object
e.g doorColour has attributes of floors and garden
Methods:
Behaviour of the object
The actions that can be performed by an object
Think of these as subroutines
e.g changeDoorColour and changeFloors
Class:
A blueprint or template to create an object
It defines the attributes and methods of the objects in that class
Object Oriented programming (OOP):
Objects
Classes
Attributes
Methods
Encapsulation:
The processing of making the attributes of an object private
Constructor:
Special type of method to create an instance of an object from a class
Instantiation:
Process of creating new instances of a class
In simple terms, creating an object from a class template
Object:
An instance of a class
To initialise a class:
Class class_name():
To initialise a constructor method:
def __innit__(self, parameters, etc)
Examples of getters:
def get_name():
return name
Setting a name in OOP using the set method:
def set_name(self):
self.name = name
Inheritance:
Where the child class inherits the attributes of a parent class
As well as having its own attributes
Advantages of Inheritance:
Avoids repeating code
As methods and attributes are shared
Therefore can be re-used
Parent class also known as:
The super class
The base class
Polymorphism:
Where different objects differently to other instances of their class
In simple terms it is the ability of an object to take on many forms
Polymorphism allows objects of different classes to be treated as objects of a common super-class.
OOP is an example of decomposition because different developers can work on different parts of the code simultaneously, which decreases programming code, whereas procedural programming is sequential and the developers cannot work on different parts
Advantages of encapsulation:
Data is protected and isn't changed inadvertently
Which reduces the risk of errors
Unless accessed using the methods provided by the object
Dynamic polymorphism:
Within an inheritance hierarchy, a subclass is able to override a method if its superclass
This allows the coder of the subclass to customise or completely replace the behaviour of that method