OOP Terms Flashcards

1
Q

What is Duck-Typing?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Polymorphism?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an Actor in object-oriented programming?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an Abstract Class?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Concretion?

A

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.’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Encapsulation?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Inheritance?

A

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.’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Method Overriding?

A

Method overriding allows a subclass to provide a specific implementation for a method that is already defined in its superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Multiple Inheritance?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an Interface?

A

An interface is a contract that defines methods a class must implement. Python uses abstract base classes (ABC) to achieve similar functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Composition?

A

Composition is a design principle where objects are composed of other objects to achieve functionality, involving instances of other classes as attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a Mixin?

A

A mixin is a special kind of class in Python used to add additional functionality to a class through multiple inheritance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a Constructor?

A

A constructor is a special method in Python defined by \_\_init\_\_, called when an object of a class is instantiated to initialize attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Destructor?

A

A destructor is a method called when an object is deleted or garbage collected in Python, defined by \_\_del\_\_.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a Static Method?

A

A static method is defined using the @staticmethod decorator and does not require access to the instance or class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a Class Method?

A

A class method is defined using the @classmethod decorator, takes cls as its first parameter, and can modify the class state.

17
Q

What is an Instance Method?

A

An instance method is a regular method in a class that operates on instance-level data, taking self as its first parameter.

18
Q

What is Method Resolution Order (MRO)?

A

MRO determines the order in which methods are inherited in a class hierarchy, using the C3 linearization algorithm.

19
Q

What is the @property Decorator?

A

The @property decorator allows a method to be accessed like an attribute, commonly used for defining getters, setters, and deleters.