csci 363 midterm review

SOLID Principles
  1. What is the Single Responsibility Principle (SRP)?
    → A class should have only one reason to change.

  2. What does the Open/Closed Principle (OCP) state?
    → Classes should be open for extension but closed for modification.

  3. What is the Liskov Substitution Principle (LSP)?
    → Subtypes must be substitutable for their base types.

  4. What does the Interface Segregation Principle (ISP) mean?
    → A class should not be forced to implement interfaces it doesn’t use.

  5. What is the Dependency Inversion Principle (DIP)?
    → High-level modules should depend on abstractions, not concrete implementations.

OOP Concepts
  1. What is encapsulation?
    → Restricting direct access to object data while exposing necessary parts.

  2. How does inheritance differ from composition?
    → Inheritance uses "is-a" relationships; composition uses "has-a" relationships.

  3. What is abstraction?
    → Hiding implementation details while exposing only essential functionality.

Design Patterns
  1. What is the purpose of the Singleton pattern?
    → Ensures only one instance of a class exists.

  2. What problem does the Factory Method pattern solve?
    → Encapsulates object creation, letting subclasses decide which class to instantiate.

  3. What is the Abstract Factory pattern used for?
    → Creates families of related objects without specifying concrete classes.

  4. How does the Builder pattern work?
    → Separates object construction from representation by building it step by step.

  5. What is the Adapter pattern?
    → Converts one interface into another to make incompatible systems work together.

  6. How does the Bridge pattern differ from the Adapter pattern?
    → Bridge separates abstraction from implementation, while Adapter makes two existing interfaces compatible.

  7. What is the Flyweight pattern?
    → Shares objects to reduce memory usage.

  8. What is the purpose of the Strategy pattern?
    → Encapsulates multiple interchangeable behaviors.

  9. How does the Observer pattern work?
    → Defines a dependency where multiple objects listen and react to changes in a subject.

  10. What is the Command pattern?
    → Encapsulates a request as an object, allowing parameterization, queuing, and logging.

  11. What does the State pattern allow an object to do?
    → Change behavior when its internal state changes.

  12. What is the Chain of Responsibility pattern?
    → Passes a request through a chain of handlers until one processes it.

Pattern Comparisons
  1. What is the key difference between Strategy and State patterns?
    → Strategy lets the client choose the behavior; State changes behavior based on internal state.

  2. When should you use the Observer pattern?
    → When multiple objects need to react to state changes in a subject.

  3. How does the Chain of Responsibility pattern improve flexibility?
    → Requests are passed through multiple handlers, allowing different handlers to process them dynamically.

  4. What are the benefits of the Builder pattern?
    → It helps construct complex objects while keeping the creation process flexible.

  5. When should you use the Adapter pattern?
    → When you need to make an existing class compatible with another interface.

  6. How do you fix a Singleton implementation that lacks thread safety?
    → Use synchronized getInstance() or double-checked locking.

  7. What’s the primary benefit of using the Bridge pattern?
    → It decouples abstraction from implementation.

  8. How does the Command pattern help in undo/redo functionality?
    → Commands can be stored in a history log, allowing undo and redo operations.

  9. What is the main drawback of the Flyweight pattern?
    → Managing shared state can be complex.

  10. How does the Factory Method align with the Open/Closed Principle?
    → New types can be added without modifying existing code.

  11. How does the Observer pattern reduce coupling?
    → Subjects and observers are loosely coupled.

  12. What’s the difference between tight coupling and loose coupling?
    → Tight coupling makes changes harder, while loose coupling improves flexibility.

  13. What is high cohesion?
    → A class focuses on a single responsibility, making it easier to maintain.

  14. What is low cohesion?
    → A class has multiple unrelated behaviors, making it difficult to maintain.

  15. What is the difference between aggregation and composition?
    → Aggregation is a weak relationship; composition is a strong relationship where the contained object cannot exist independently.

  16. Why should composition be preferred over inheritance?
    → It avoids deep inheritance hierarchies and helps achieve loose coupling.

robot