OOP Terms Flashcards
What is Duck-Typing?
Duck-typing is a concept in dynamic programming languages like Python where the type or class of an object is determined by its behavior (methods and properties) rather than its explicit inheritance.
What is Polymorphism?
Polymorphism allows objects of different classes to be treated as objects of a common superclass.
Example: both ‘Cat’ and ‘Dog’ classes have a ‘speak’ method, and they can be used interchangeably in code expecting objects with a ‘speak’ method.
What is an Actor in object-oriented programming?
An actor refers to a user, role, or external system that interacts with a class or system. It relates to the Single Responsibility Principle, where a class should serve only one actor.
What is an Abstract Class?
An abstract class is a class that cannot be instantiated and serves as a blueprint for subclasses.
In Python, abstract classes are implemented using the ‘abc’ module and must contain at least one abstract method (annotated with @abstractmethod).
What is Concretion?
A concretion is a concrete implementation of an abstraction, such as a class that implements an abstract base class or interface.
For example, a ‘Bird’ abstract class might have concrete subclasses like ‘Sparrow’ and ‘Penguin.’
What is Encapsulation?
Encapsulation is the bundling of data (attributes) and methods that operate on the data into a single unit (class) and restricting direct access to some components.
What is Inheritance?
Inheritance is a mechanism where one class (subclass) inherits the attributes and methods of another class (superclass), allowing code reuse and establishing an ‘is-a’ relationship.
In Python: class Dog(Animal):
means ‘Dog’ is a subclass of ‘Animal.’
What is Method Overriding?
Method overriding allows a subclass to provide a specific implementation for a method that is already defined in its superclass.
What is Multiple Inheritance?
Multiple inheritance is a feature in Python where a class can inherit from more than one parent class.
Example: class C(A, B):
where C
inherits attributes and methods from both A
and B
.
What is an Interface?
An interface is a contract that defines methods a class must implement. Python uses abstract base classes (ABC) to achieve similar functionality.
What is Composition?
Composition is a design principle where objects are composed of other objects to achieve functionality, involving instances of other classes as attributes.
What is a Mixin?
A mixin is a special kind of class in Python used to add additional functionality to a class through multiple inheritance.
What is a Constructor?
A constructor is a special method in Python defined by \_\_init\_\_
, called when an object of a class is instantiated to initialize attributes.
What is a Destructor?
A destructor is a method called when an object is deleted or garbage collected in Python, defined by \_\_del\_\_
.
What is a Static Method?
A static method is defined using the @staticmethod
decorator and does not require access to the instance or class.