OOP & SOLID in Python - Interview Guide
OOP Summary
Object-Oriented Programming organizes code using objects that combine data and behavior. Main
pillars:
Encapsulation
class Device:
def __init__(self):
self._status = "offline"
def turn_on(self):
self._status = "online"
Abstraction
from abc import ABC, abstractmethod
class Service(ABC):
@abstractmethod
def run(self):
pass
Inheritance
class Animal:
def speak(self):
print("Sound")
class Dog(Animal):
def speak(self):
print("Bark")
Polymorphism
def make_sound(animal):
[Link]()
SOLID Principles
S - Single Responsibility
class Report:
def generate(self):
pass
class ReportPrinter:
def print(self, report):
pass
O - Open/Closed
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
L - Liskov Substitution
class Bird:
def fly(self):
pass
I - Interface Segregation
class Printer:
def print(self):
pass
D - Dependency Inversion
class Database:
def save(self):
pass
class Service:
def __init__(self, db):
[Link] = db
Practice Questions (EPAM Style)
- Explain difference between list and tuple
- What is GIL in Python?
- Difference between threading and asyncio
- What is a decorator?
- Explain context manager
- What is dependency injection?
- Explain SOLID principles
- What is difference between multiprocessing and threading?
- What is async/await?
- Explain difference between classmethod and staticmethod
- How would you design a scalable system?
- What is REST API?
- Difference between SQL and NoSQL
- What is Docker and why use it?