SOLID & OOP Principles (50 Qs)•Part 1: Core SOLID Principles & Fundamentals (1 - 10)
What is the Law of Demeter (Principle of Least Knowledge) and how do you spot train-wreck code?
senior Levelsolid-principlesCore SOLID Principles
In Simple Words: A method should only call methods on:
- Itself (
this). - Its parameters.
- Objects it instantiated directly.
- Its direct member fields.
Train-Wreck Violation:
order.getCustomer().getAddress().getCity().getZipCode() exposes the internal structure of 4 classes! Refactor to order.getShippingZipCode().