OOP Terminology
Classes:
- Class — blueprint for creating objects.
- Instance — general «concept» of being an object of class.
- Object — actual entity in memory.
- Abstract Class (vs Concrete Class) — class that cannot be instantiated (Python: ABC and @abstractmethod). Can contain abstract methods. Subclasses of abstract class are required to provide implementation for abstract methods.
- Subclass (Derived Class) — class that interits from Superclass (Base class).
- Metaclass — class which instances are classes.
Methods:
- Function — block of code that performs a specific task
- Method — function that is associated with an object (instance of a class)
- Private methods — …
- Static methods — methods that belong to a class rather than an instance of a class (Python: @staticmethods).
- Abstract methods — methods of abstract class (they then need to be implemented in subclasses of abstract class).
- Virtual methods — methods that are declared within a base clas and that are supposed to be overriden by a derived class.
Attributes:
- Attributes — data members of an object (variables)
- Private attributes — …
- Static/Class Attributes — attributes belonging to a class (not instance)
- Dynamic/Instance Attributes — attributes belonging to an object (not class)
- Properties — attributes that have getters and setters methods associated with them
Main principles
Encapsulation
Bundling of data (attributes) and methods that operate on that data within one unit, typically a class.
Polymorphism
Polymorphism allows objects of different classes to be treated as objects of a common superclass.
Polymorphism is usually (for example in Python) achieved through method overriding. This allows for the same method name to be used for different types of objects.
Abstraction
Abstraction is a process of hiding implementation details and showing only the functionality to the user. For example, abstraction in Python is achived through ABC from «abc» lib.
Inheritance
Inheritance is mechanism that allows one class to acquire (inherit) methods and attributes of it’s superclass. Those methods can then be overriden or extended.
Python supports single and multiple inheritance (class can inherit from multiple superclasses).