Pergunta de entrevista da empresa Fidelity Investments

What is inheritance, benefits, pitfalls?

Resposta da entrevista

Sigiloso

25 de out. de 2024

Inheritance is incredibly useful for encapsulation. It promotes the re-usability of code without rewriting the code, for example if you extend UIButton on a class, you don't have to rewrite all Apples button code. One of the primary disadvantages of inheritance is tight coupling. When a subclass inherits from a superclass, it becomes tightly coupled to the superclass. This means that any changes to the superclass can have a ripple effect on the subclass, making it difficult to maintain and modify the code. Also you inherit everything even when you might not need certain functions from the parent class, this can introduce a lot of boilerplate code.