How can encapsulation, abstraction, inheritance and polymorphism help or hurt test code?
Answer
Encapsulation and small abstractions can centralize stable behaviour; polymorphism can support interchangeable drivers. Deep inheritance and hidden side effects make tests harder to understand. Use OOP where it reduces change cost, not to imitate production architecture.
Strong answer includes
- explains principles through test code
- warns about deep inheritance
- optimizes readability
Practical example
A page-object base class grows five levels of inheritance to share small bits of logic, and a new hire spends an hour just tracing which parent class actually sets up the login state; flattening it into one class with a couple of composed helper objects makes the same behaviour obvious at a glance.