5 Questions
According to the Open Closed Principle, a module should be:
open for extension but closed for modification
What is the key to the Open Closed Principle?
Abstraction
According to the Liskov Substitution Principle, subclasses should be substitutable for their base classes. This means that:
if some function takes an argument of type Base, it should be legal to pass in an instance of Derived to that function
The Dependency Inversion Principle emphasizes:
abstraction over concrete dependencies
The Interface Segregation Principle advocates for:
client-specific interfaces over general-purpose interfaces
Study Notes
- Class design principles are introduced and discussed, including the Open Closed Principle, Liskov Substitution Principle, Dependency Inversion Principle, and Interface Segregation Principle, in the context of SWE 316: Software Design & Architecture.
- The Open Closed Principle: a module should be open for extension but closed for modification. This means that we can change what the module does without modifying the module's source code. Abstraction is used to achieve this.
- Example: The LogOn function depends only on the Modem interface, not on a specific modem implementation. This allows for new modems to be added without modifying the LogOn function.
- The Liskov Substitution Principle: subclasses should be substitutable for their base classes. If a function accepts an argument of base class type, it should be able to accept an instance of the derived class without causing any issues.
- SWE 316 covers these class design principles, with the Open Closed Principle focusing on extendability, Liskov Substitution Principle on substitutability, and the text providing examples for understanding their practical applications.
Test your knowledge on principles of class design including the Open Closed Principle, Liskov Substitution Principle, Dependency Inversion Principle, and Interface Segregation Principle.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free