SOFTWARE ENGINEERING

SOFTWARE DESIGN

DESIGN PATTERNS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
“Favor composition over inheritance.” says:
A
Use the Composite Pattern instead of inheritance.
B
IS-A is always better than HAS-A
C
HAS-A can be better than IS-A
D
Do not use inheritance.Show answersExplanationPreviousNext
Explanation: 

Detailed explanation-1: -One more benefit of composition over inheritance is testing scope. Unit testing is easy in composition because we know what all methods we are using from another class. We can mock it up for testing whereas in inheritance we depend heavily on superclass and don’t know what all methods of superclass will be used.

Detailed explanation-2: -Inheritance and composition are two programming techniques developers use to establish relationships between classes and objects. Whereas inheritance derives one class from another, composition defines a class as the sum of its parts.

Detailed explanation-3: -This means that a method defined on a parent class is going to be available on its subclasses. Subclasses are allowed to overwrite any parent method.

There is 1 question to complete.