Which of the following best describes the Single Responsibility Principle (SRP) in software engineering?
Think about how responsibilities affect the reasons for changing a class.
The Single Responsibility Principle states that a class should have only one reason to change, meaning it should focus on a single responsibility. This makes the code easier to maintain and understand.
What does the Open/Closed Principle (OCP) state about software entities like classes or modules?
Consider how new features should be added without changing existing code.
The Open/Closed Principle means software entities should allow their behavior to be extended without modifying their source code, helping to avoid bugs and maintain stability.
Given a base class Bird with a method fly(), and a subclass Penguin that cannot fly, which design violates the Liskov Substitution Principle (LSP)?
Think about substituting a subclass where the base class is expected.
LSP states that subclasses should be replaceable by their base classes without altering the correctness of the program. Throwing an exception in fly() breaks this because Penguin cannot be used where Bird is expected.
Which statement correctly compares coupling and cohesion in software design?
Consider how components depend on each other and how focused their tasks are.
Low coupling means components have few dependencies, and high cohesion means components have focused, related tasks. Together, they make software easier to maintain and understand.
In a system where high-level modules depend directly on low-level modules, which change best applies the Dependency Inversion Principle (DIP)?
Think about how to reduce direct dependencies between different levels of modules.
DIP states that both high-level and low-level modules should depend on abstractions, not on concrete implementations. This reduces coupling and improves flexibility.