1. Home
  2. Explore
  3. Computer Science
  4. Design Patterns Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Design Patterns Overview

  • 43Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Design Patterns Fundamentals
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What are design patterns?

Tap to flipClick to flipspace

Well-tested, reusable, optimal solutions to common software engineering problems; they are like solution templates.

Or swipe the card

43 cards

  1. What are design patterns?

    Well-tested, reusable, optimal solutions to common software engineering problems; they are like solution templates.

  2. Why should developers use design patterns?

    They save time, are optimized, provide a common meta-language for developers, facilitate good communication, and lead to well-organized software design.

  3. What are the three families of design patterns?

    Creational, Structural, and Behavioral.

  4. What do creational design patterns deal with?

    Object creation mechanisms; they create objects in flexible and highly adaptable ways.

  5. What do structural design patterns deal with?

    Managing complex object hierarchies and composing relationships among entities efficiently.

  6. What do behavioral design patterns deal with?

    Improving interaction and communication between objects; they provide loosely coupled ways for objects to exchange messages.

  7. Name the seven design patterns covered in this course.

    Singleton, Factory Method, Builder, Adapter, Strategy, Observer, and State.

  8. What is software architecture according to the course?

    A high-level blueprint that shows everybody involved what is being worked on, providing predictability and coherence.

  9. What are the hallmarks of good architecture?

    Loose coupling, separation of concerns, Law of Demeter (LoD), and the SOLID principles.

  10. What is loose coupling?

    Weak knowledge association between components; changes to one component least affect others.

  11. What is separation of concerns?

    Breaking architecture into tiers (e.g., presentation, business, data access) using modularization and encapsulation.

  12. What is the Law of Demeter (LoD)?

    Each unit should only talk to its immediate friends; a given object should assume as little as possible about the structure of anything else.

  13. State the Single Responsibility Principle (SRP).

    There should never be more than one reason for a class to change; each class should have only one central responsibility.

  14. State the Open/Closed Principle (OCP).

    Software entities should be open for extension but closed for modification.

  15. State the Liskov Substitution Principle (LSP).

    Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.

  16. State the Interface Segregation Principle (ISP).

    Clients should not be forced to depend upon interfaces that they do not use.

  17. State the Dependency Inversion Principle (DIP).

    Depend upon abstractions, not concretions.

  18. What is UML used for in this course?

    To document design patterns using class diagrams (structure) and sequence diagrams (interaction).

  19. What does a class diagram capture?

    Class information (attributes, operations) and class relationships (generalization, association, dependency).

  20. What does a sequence diagram capture?

    Interaction information: actors, method calls, and message exchange over time.

  21. What is an interface contract in Python?

    An abstract class with all methods as abstract (using ABC and abstractmethod) with no implementation; subclasses must implement all abstract methods.

  22. What is an abstract class in Python?

    A class derived from ABC that can have both abstract methods (to be implemented) and concrete methods (with implementation) as well as instance variables.

  23. How do you create an abstract class in Python?

    Import ABC and abstractmethod from abc; the class inherits from ABC; abstract methods are decorated with @abstractmethod.

  24. What is encapsulation in OOP?

    Gathering relevant data and functionality in one place, controlling complexity by putting complicated code behind easy-to-use methods, and controlling access to data (e.g., via getters/setters with preconditions).

  25. What is inheritance in OOP?

    Allowing a class (child) to inherit properties and behavior from a parent class, enabling code reuse and establishing an 'is-a' relationship.

  26. What is the purpose of the Singleton pattern?

    To ensure a class has only one instance and provide easy global access to that instance.

  27. What are common use cases for Singleton?

    Loggers, caching, thread pools, database connections, configuration access.

  28. What is lazy instantiation in Singleton?

    The Singleton instance is created only when it is first needed (e.g., in the get_instance method).

  29. What is eager instantiation in Singleton?

    The Singleton instance is created when the class is loaded into memory, before it is requested.

  30. How do you make a Singleton thread-safe?

    Use a lock (e.g., threading.Lock) to protect the critical section where the instance is created.

  31. What is a metaclass in Python?

    A class that defines the behavior for creating other classes; by default, all classes inherit from type.

  32. How does the Factory Method pattern solve the problem of object creation?

    It abstracts object creation behind a factory method, so the caller does not need to know the concrete class; objects are created through an abstraction.

  33. What is the difference between the classic Gang of Four Factory Method and the simple (parameterized) Factory Method?

    Classic: Each concrete product has a corresponding concrete factory class. Simple: A single factory with a parameter that determines which concrete product to create.

  34. What is the Builder pattern used for?

    To separate the construction of a complex object from its representation, so that the same construction process can create different representations.

  35. What is the role of the Director in the Builder pattern?

    The director controls the construction process by delegating to a builder object, calling the appropriate build steps.

  36. What is the Adapter pattern?

    A structural pattern that converts the interface of a class into another interface that the client expects, allowing classes with incompatible interfaces to work together.

  37. What are the key steps to design an Adapter?

    1. Identify the adaptee (service). 2) Declare the client interface. 3) Create an adapter class implementing the client interface and referencing the adaptee. 4) Implement client methods by delegating to the adaptee with necessary conversion.
  38. What is the Strategy pattern?

    A behavioral pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable. The algorithm can vary independently from clients that use it.

  39. What is the Observer pattern?

    A behavioral pattern where a subject maintains a list of observers and notifies them automatically of any state changes, usually by calling an update method.

  40. What is the state pattern?

    A behavioral pattern that allows an object to alter its behavior when its internal state changes. The object appears to change its class.

  41. How does the State pattern differ from Strategy?

    In Strategy, the algorithm objects are independent and unaware of each other. In State, the states know about each other and can transition; the context's behavior changes with internal state.

  42. What are the three rules of Conway's Game of Life?

    1. Any live cell with 2 or 3 live neighbors survives. 2) Any dead cell with exactly 3 live neighbors becomes alive (birth). 3) All other live cells die, and all other dead cells stay dead.
  43. What are the design steps for the Game of Life assignment?

    1. Write down general workflow, define inputs/outputs. 2) Outline main agents (objects). 3) Define how objects communicate. 4) Choose design patterns. 5) Build proof of concept. 6) Refine iteratively.
Card 1 of 43
Card 1 of 43

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent