Filter by the role you are applying for, open a question, and practise explaining the answer out loud. Mark it practised when you can.
Why they ask this: Mid-level and good junior candidates are expected to know how to keep code maintainable.
Answer
Why they ask this: Checks design maturity; deep inheritance trees are a common source of rigid code.
Answer
KhaltiGateway class instead of adding another if to existing code.Do not just recite the list: give one real example from your own project of a principle you applied, or one you broke and later fixed.
// Inheritance: every new notification channel needs a new subclass
class SmsOrderNotifier extends OrderNotifier { /* ... */ }
// Composition: inject the channel
final class OrderNotifier
{
public function __construct(private NotificationChannel $channel) {}
public function notify(Order $order): void
{
$this->channel->send($order->customer, "Order #{$order->id} confirmed");
}
}Inheritance is still fine for a true, stable "is a" relationship with shared behaviour. Flutter is a good example of composition: UIs are built by nesting small widgets rather than extending big ones.