Software Design Principles Quiz
40 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the primary problem with the design of the Employee class described?

  • It contains methods that are unrelated to its main purpose.
  • It violates the Single Responsibility Principle by having multiple responsibilities. (correct)
  • It lacks adequate documentation for its methods.
  • It is too complex for developers to understand.
  • Which actor is responsible for computing employee salaries in the flawed design?

  • Database administrator
  • Human resource personnel
  • Accounting personnel (correct)
  • Software developer
  • What is a consequence of multiple methods depending on a single class in the flawed design?

  • Increased performance due to modularization.
  • Improved communication between different actors.
  • Changes to one method may inadvertently affect others. (correct)
  • All methods will function correctly under all changes.
  • What does the Single Responsibility Principle (SRP) suggest?

    <p>Classes should have only one reason to change.</p> Signup and view all the answers

    What should be done to resolve the multiple responsibilities within the Employee class?

    <p>Divide the responsibilities into separate classes.</p> Signup and view all the answers

    What is one potential risk mentioned when changing the totalHoursWorked variable?

    <p>Accounting and HR teams may receive inconsistent data.</p> Signup and view all the answers

    In the suggested solution using SRP, what does each new class hold?

    <p>Only the code necessary for its particular method.</p> Signup and view all the answers

    What key consequence is highlighted regarding bad design architecture?

    <p>It leads to confusion and errors between different actors.</p> Signup and view all the answers

    What does the constructor of the UserManager class receive?

    <p>An instance of INotifier</p> Signup and view all the answers

    Which method of UserManager uses the instance of INotifier?

    <p>changePassword()</p> Signup and view all the answers

    What principle does the design of UserManager and INotifier conform to?

    <p>Dependency Inversion Principle (DIP)</p> Signup and view all the answers

    Which of the following is an example of a low-level class mentioned in the design?

    <p>EmailNotifier</p> Signup and view all the answers

    What does the second part of the Dependency Inversion Principle state?

    <p>Details should depend upon abstractions.</p> Signup and view all the answers

    What are the notifiers like EmailNotifier and SMSNotifier an example of?

    <p>Implementations of the INotifier interface</p> Signup and view all the answers

    Following the DIP, how would a requirement change in notification features affect UserManager code?

    <p>It could be changed without affecting UserManager.</p> Signup and view all the answers

    In the context of the provided design, what does INotifier represent?

    <p>An abstraction for notification behavior</p> Signup and view all the answers

    What issue arises when the IOrderProcessor interface is modified to include methods for credit card payments?

    <p>The CashOnDeliveryOrderProcessor must implement additional methods it does not need.</p> Signup and view all the answers

    How does the Interface Segregation Principle (ISP) suggest addressing the problem with IOrderProcessor?

    <p>By splitting methods into multiple interfaces.</p> Signup and view all the answers

    In the provided solution using ISP, which methods does the IOrderProcessor interface contain?

    <p>validateShippingAddress() and processOrder()</p> Signup and view all the answers

    What method is included in the IOnlineOrderProcessor interface?

    <p>validateCardInfo()</p> Signup and view all the answers

    Which class is designed to handle online credit card payments as per the solution?

    <p>OnlineOrderProcessor</p> Signup and view all the answers

    What is a consequence of the original design that violates the ISP?

    <p>It increases the overall complexity of the payment processing system.</p> Signup and view all the answers

    What does the CashOnDeliveryOrderProcessor class do in the modified design?

    <p>Throws exceptions when additional methods are unnecessary.</p> Signup and view all the answers

    What principle is being violated by forcing the CashOnDeliveryOrderProcessor to implement additional methods?

    <p>Interface Segregation Principle (ISP)</p> Signup and view all the answers

    What does the License class exemplify in relation to its derived classes?

    <p>They can universally substitute the License class.</p> Signup and view all the answers

    What is the main idea of the Interface Segregation Principle (ISP)?

    <p>It is better to have multiple small interfaces than one large one.</p> Signup and view all the answers

    What issue arises from implementing the IOrderProcessor interface with cash-on-delivery?

    <p>Methods become redundant when not used in a class.</p> Signup and view all the answers

    Why is it problematic for the CashOnDeliveryOrderProcessor to throw an exception in validateCardInfo()?

    <p>It can cause confusion about the functionality of the interface.</p> Signup and view all the answers

    What is a possible consequence of a violation of the Liskov Substitution Principle (LSP)?

    <p>The system’s architecture may break.</p> Signup and view all the answers

    What is the e-commerce example's primary design flaw regarding payment processing?

    <p>Not accommodating different payment processing classes.</p> Signup and view all the answers

    In the context of software design, what does the term 'interface' refer to?

    <p>An abstract blueprint that defines methods without implementation.</p> Signup and view all the answers

    What should developers ideally do when interfaces become too large and complex?

    <p>Break down the large interface into smaller, more focused interfaces.</p> Signup and view all the answers

    What does the Open/Closed Principle (OCP) state regarding class modification?

    <p>A class should be closed for modification and open for extension.</p> Signup and view all the answers

    Which of the following is NOT a valid way to implement the Open/Closed Principle?

    <p>Utilizing an abstract class for modifications.</p> Signup and view all the answers

    What is a requirement of the Liskov Substitution Principle regarding derived classes?

    <p>Derived classes should behave identically regardless of which class is used.</p> Signup and view all the answers

    In the example of the License class, what determines if the design conforms to the Liskov Substitution Principle?

    <p>The algorithms used for fee calculation in derived classes.</p> Signup and view all the answers

    What could be a consequence of adding a new requirement to an existing software if not adhering to OCP?

    <p>Increased risk of introducing bugs in other functions.</p> Signup and view all the answers

    Which statement best describes how to properly use the Open/Closed Principle?

    <p>Create new derived classes to introduce additional functionalities.</p> Signup and view all the answers

    Why is the concept of abstraction functional in implementing the Open/Closed Principle?

    <p>It enables extension of classes without breaking existing code.</p> Signup and view all the answers

    What can be inferred about derived classes under the Liskov Substitution Principle?

    <p>They should not alter the expected behavior of the base class.</p> Signup and view all the answers

    Study Notes

    Single Responsibility Principle (SRP)

    • The Single Responsibility Principle states that a class should have only one reason to change.
    • A class with multiple responsibilities violates the SRP.
      • For example, a class designed to manage employee data, calculate pay, and generate reports violates the SRP.
    • To adhere to the SRP, create separate classes for each responsibility.
      • Create an Employee class, a Payroll class, and a ReportGenerator class.

    Open/Closed Principle (OCP)

    • The Open/Closed Principle states that software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
    • To adhere to the OCP, create abstract classes, interfaces, or abstract methods.
      • New functionalities can be added by creating new classes or methods that extend the existing base classes.
      • This prevents the need to change the original code, reducing the risk of introducing bugs.

    Liskov Substitution Principle (LSP)

    • The Liskov Substitution Principle states that derived classes should be able to substitute their base class without affecting the program's behavior.
    • Derived classes should implement the same functionality as the base class, possibly with additional features.
    • This ensures that code using the base class will work correctly with any of its derived classes.

    Interface Segregation Principle (ISP)

    • The Interface Segregation Principle states that clients should not be forced to depend on methods they do not use.
    • Create multiple smaller interfaces instead of one large interface.
    • Each interface should be specific to a specific group of methods, allowing clients to implement only the methods they need.

    Dependency Inversion Principle (DIP)

    • The Dependency Inversion Principle states that high-level modules should not depend on low-level modules. Both should depend on abstractions.
    • Abstractions (interfaces or abstract classes) should not depend on details. Details should depend on abstractions.
    • In practice, this means that classes should be decoupled by using interfaces or abstract classes to define dependencies.
      • Inject dependencies through constructors or properties, allowing for easy substitution of implementations.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    03_Handout_1(38).pdf

    Description

    Test your knowledge on the key software design principles, including the Single Responsibility Principle (SRP), Open/Closed Principle (OCP), and Liskov Substitution Principle (LSP). This quiz covers fundamental concepts to help you understand and apply these principles in your programming projects.

    More Like This

    Biology: Single-Celled Organisms
    12 questions
    Single Stranded Binding Proteins Quiz
    10 questions
    The Danger of A Single Story Overview
    7 questions
    Use Quizgecko on...
    Browser
    Browser