Which design principle is violated if a superclass is aware of its subclasses?

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
When a superclass is aware of its subclasses, it violates the principle of encapsulation. Encapsulation refers to the concept of bundling data and the methods that operate on that data into a single unit or class. In object-oriented programming, classes should not have direct knowledge of their subclasses to promote loose coupling and maintainability. Instead, subclasses should inherit behavior and attributes from the superclass without the superclass needing to know specific details about its subclasses. Violating this principle can lead to code that is less flexible and harder to maintain.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *