📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      According to SOLID principles, the Liskov Substitution

      Principle (LSP) primarily focuses on:
      A Objects in a program should be replaceable with instances of their subclasses without altering the correctness of the program Correct Answer Incorrect Answer
      B Software entities (classes, modules, functions) should be open for extension but closed for modification Correct Answer Incorrect Answer
      C A class should have only one reason to change, following a single responsibility Correct Answer Incorrect Answer
      D Clients should not be forced to depend on interfaces they do not use Correct Answer Incorrect Answer
      E Dependencies should be abstract, not concrete implementations Correct Answer Incorrect Answer

      Solution

      The Liskov Substitution Principle (LSP) ensures that derived classes (or subclasses) must be able to substitute their parent classes without affecting the behavior of the program. This principle is fundamental in object-oriented programming as it ensures that any derived class can stand in for its base class, maintaining the expected behavior. Violation of LSP usually indicates design issues, such as improper inheritance structures. Why other options are wrong: b) Open/Closed Principle : This principle emphasizes that software entities should be extendable without modifying existing code. This is not the Liskov Substitution Principle. c) Single Responsibility Principle : States that a class should only have one reason to change, which relates to the design of class responsibilities, not LSP. d) Interface Segregation Principle : Focuses on minimizing interface dependencies, but it does not relate to class substitution. e) Dependency Inversion Principle : Advocates for abstracting dependencies, focusing on design-level issues unrelated to class substitution.

      Practice Next

      Relevant for Exams:

      ask-question