Unit 2 Flashcards
What does the acronym SOLID stand for in software design?
Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
SOLID principles aim to make software more understandable, maintainable, and extensible.
Who presented the SOLID design principles?
Robert Martin
These principles were introduced in ‘Design Principles and Design Patterns’ (2000).
What is the first principle of SOLID design?
Single Responsibility Principle
A module should be responsible to one, and only one, actor.
Define Single Responsibility Principle.
A class should have only one reason to change.
Responsibility refers to the reason for change related to the role a class performs.
What is an anti-pattern of the Single Responsibility Principle?
The ‘God’ class
It knows everything, does everything, and changes for everything, making it a maintenance nightmare.
What does the Open/Closed Principle state?
Software entities should be open for extension, but closed for modification.
This means existing behaviors do not change, while new features can be added.
What is the importance of the Liskov Substitution Principle?
Objects in a program must be replaceable by subtypes without altering correctness.
Inheritance implies substitutability.
What does the Interface Segregation Principle emphasize?
Clients should not depend on interfaces they do not use.
It promotes organizing interfaces around tasks and separating them for different functionalities.
What is the Dependency Inversion Principle?
High-level modules should not import anything from low-level modules. Both should depend on abstractions.
This principle aims to reduce dependency and improve flexibility.
Fill in the blank: A module should be responsible to one, and only one, _______.
actor
What problem does the ‘God’ class exemplify?
Maintenance nightmare due to excessive responsibilities.
Changes in specification require updating the entire class.
What should be the relationship between high-level and low-level modules according to the Dependency Inversion Principle?
Both should depend on abstractions.
This avoids brittleness and promotes reusability.
What does the term ‘clopen’ refer to in the context of the Open/Closed Principle?
A combination of open and closed.
It describes the need to separate what is open for extension and what is closed for modification.
What is a major consequence of violating the Liskov Substitution Principle?
Subtypes may violate the promises made by their supertype.
This can lead to unexpected behavior in programs.
Give an example of a design flaw that arose in Python 2.5.
Fundamental design flaws that required breaking backwards compatibility to fix.
This led to the release of Python 3.0.
What does the Interface Segregation Principle suggest about the design of interfaces?
Organize interfaces around tasks and separate them for different functionalities.
This approach prevents clients from depending on unused methods.
What is a key benefit of having thin interfaces?
Easier to extend and maintain.
They lead to more focused behaviors that are easier to test.
True or False: The Dependency Inversion Principle states that abstractions should depend on details.
False
It states that details should depend on abstractions.
What does it mean for a class to have a single responsibility?
It should only have one reason to change.
This relates to the class’s role within the software.
What is the purpose of source code documentation?
To explain the functionality and usage of the code.
Define self-documenting code.
Code that explains itself through its structure and naming conventions.
What is Javadoc documentation?
A tool that generates API documentation in HTML format from Java source code.
Why is programming style important?
It enhances readability and maintainability of code.
Fill in the blank: ‘You read code ______ as often as you write it.’
10x