A Python class 'Shape' defines an abstract method 'area'. Subclasses 'Circle' and 'Square' implement 'area'. A function 'calculate_area(shape)' expects a 'Shape' instance. Which principle ensures that the function works correctly without knowing the specific subclass?
Trap 1: Interface Segregation Principle
ISP is about keeping interfaces small.
Trap 2: Single Responsibility Principle
SRP is about each class having one responsibility.
Trap 3: Dependency Inversion Principle
DIP is about high-level modules not depending on low-level modules.
- A
Interface Segregation Principle
Why wrong: ISP is about keeping interfaces small.
- B
Liskov Substitution Principle
LSP ensures that any subclass can replace the base class without breaking the function.
- C
Single Responsibility Principle
Why wrong: SRP is about each class having one responsibility.
- D
Dependency Inversion Principle
Why wrong: DIP is about high-level modules not depending on low-level modules.