Structural Design Patterns Quiz

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 purpose of the Flyweight pattern?

  • To enable remote service object communication.
  • To provide access control for heavyweight objects.
  • To manage client request histories efficiently.
  • To reduce memory requirements by sharing common data. (correct)

Which of the following is a situation where the Proxy pattern is most beneficial?

  • When clients need constant access to a service object.
  • When the service object is located on a remote server. (correct)
  • When no access control is required for clients.
  • When all service objects are lightweight.

Which entity in the Flyweight pattern is responsible for creating and managing shared objects?

  • Flyweight Factory (correct)
  • Concrete Flyweight
  • Client
  • Unshared Concrete Flyweight

What might be a reason to use a Proxy for a service object?

<p>To ensure only specific clients can access the service. (C)</p> Signup and view all the answers

In the context of the Proxy pattern, what role does the Real Subject play?

<p>It is the actual implementation that the Proxy delegates to. (D)</p> Signup and view all the answers

When should you use the Adapter pattern?

<p>When an existing class interface is incompatible with your code. (A)</p> Signup and view all the answers

What is a primary reason to use the Decorator pattern?

<p>To enable assigning extra behaviors to objects at runtime (B)</p> Signup and view all the answers

What is a primary use case for the Bridge pattern?

<p>To allow for concrete implementations to vary at runtime. (A)</p> Signup and view all the answers

Which of the following is NOT an entity in a class diagram for the Decorator pattern?

<p>Subsystem Classes (C)</p> Signup and view all the answers

What does the Composite pattern aim to achieve?

<p>To handle collections with a simple interface while hiding complexity. (C)</p> Signup and view all the answers

When is it inappropriate to use inheritance according to the content?

<p>When it's awkward or not possible to extend behavior using inheritance (D)</p> Signup and view all the answers

Which of the following entities is NOT a part of the Adapter class diagram?

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

In which scenario would the Composite pattern be the least effective?

<p>When traversing a simple linear list of objects. (C)</p> Signup and view all the answers

What does a Facade pattern provide?

<p>A minimal interface to a complex subsystem (D)</p> Signup and view all the answers

What would be a suitable use case for the Flyweight pattern?

<p>When reuse of shared objects is crucial to save memory (D)</p> Signup and view all the answers

Which of the following statements is true regarding the Bridge pattern?

<p>It allows for the creation of multiple independent class hierarchies. (B)</p> Signup and view all the answers

What is the primary role of the Decorator in the Decorator pattern?

<p>To enhance objects with new behavior (C)</p> Signup and view all the answers

Which pattern would be best suited for hiding the complexity of traversing nested data structures?

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

When might you prefer to use the Facade pattern?

<p>When you require a simplified interface to a complex system (B)</p> Signup and view all the answers

What is the role of the 'Adaptee' in the Adapter pattern?

<p>To provide functionality that is being adapted. (A)</p> Signup and view all the answers

Which statement about the Flyweight pattern is true?

<p>It optimizes memory usage by sharing objects (C)</p> Signup and view all the answers

Flashcards

Adapter Pattern

A design pattern that allows objects with incompatible interfaces to work together.

Adapter Components

Includes Target (client's expected interface), Adaptee (original incompatible class) and the Adapter (bridge between them).

Bridge Pattern

A design pattern that decouples an abstraction from its implementation. Allows switching implementations at runtime.

Bridge Components

Includes Abstraction, Refined Abstraction (Implementation), Implementor, and Concrete Implementor to achieve decoupling.

Signup and view all the flashcards

Composite Pattern

Treats individual objects and groups of objects uniformly. Hides complexity in a collection.

Signup and view all the flashcards

Composite Use Cases

Useful when you want to treat a hierarchy of objects as a single object, to reduce code duplication for traversal.

Signup and view all the flashcards

Structural Pattern

Design patterns organizing classes and objects into larger structures.

Signup and view all the flashcards

Behavioral Pattern (Recap)

Focuses on interactions between objects.

Signup and view all the flashcards

Flyweight Pattern

A design pattern that minimizes memory usage by sharing objects that are otherwise identical. It effectively reuses existing objects for similar requests rather than repeatedly creating new ones.

Signup and view all the flashcards

Flyweight Example: Usage

In a system where many objects have shared data, store the shared data in a centralized location and have objects reference that shared data instead of storing it individually.

Signup and view all the flashcards

Proxy Pattern

A design pattern where an object acts as an intermediary or placeholder for another object, controlling access to that object.

Signup and view all the flashcards

Proxy Use Case: Heavyweight Object

When an object is expensive to create or maintain, use a proxy to delay its creation until it's absolutely needed. This can improve performance, especially if the object is rarely accessed.

Signup and view all the flashcards

Proxy Use Case: Remote Object

A proxy object can handle communication with a remote object, providing a simplified local interface for the client. It hides the complexity of remote interactions.

Signup and view all the flashcards

Decorator Pattern

A design pattern that allows adding extra behaviors to objects at runtime without modifying the original object's code. It's used when inheritance is inconvenient or impossible.

Signup and view all the flashcards

Component Interface

The common interface that both the decorated objects and decorators implement. It defines the methods that can be decorated.

Signup and view all the flashcards

Concrete Component

The actual object to be decorated. It implements the Component interface.

Signup and view all the flashcards

Decorator

An object that wraps another object (Concrete Component) and provides additional functionality.

Signup and view all the flashcards

Concrete Decorator

Specific types of decorators that implement enhancements like luxury fittings or bulletproofing in the plane example.

Signup and view all the flashcards

Facade Pattern

A design pattern that provides a simplified interface to a complex subsystem, hiding its intricate details. It simplifies access to a complex system.

Signup and view all the flashcards

Subsystem Classes

The collection of complex classes that the Facade pattern simplifies. They represent the intricate parts of the subsystem.

Signup and view all the flashcards

Study Notes

Structural Design Patterns

  • Structural patterns describe how to assemble objects and classes into larger structures while maintaining flexibility and efficiency.

Adapter

  • Allows objects with incompatible interfaces to work together.
  • Adapts an object's interface to match the interface expected by the client.
  • Example: using an XML data provider with an application that expects JSON format. This requires an adapter.

Bridge

  • Splits a large class or closely related classes into two separate hierarchies (abstraction and implementation).
  • Allows independent development of abstraction and implementation.
  • This improves maintainability and flexibility.
  • Example: Graphical shapes in various colors. A single Shape abstract class can be combined with multiple Color implementations, decoupling them in bridge pattern.

Composite

  • Creates a tree structure where individual objects and groups of objects are treated as a single unit.
  • Client code interacts with components similarly regardless of whether they are individual or composed of several components.
  • Example: Hierarchical military structure or an order with various nested items.

Decorator

  • Allows adding new functionality to objects dynamically without modifying their structure.
  • Decorators wrap the original object.
  • Example: Adding features to a coffee beverage (e.g., milk, cream, sugar).

Facade

  • Provides a simplified interface to a complex subsystem.
  • Hides the complexity of the subsystem from the client.
  • Example: placing orders by phone, which simplifies communication with the underlying components (packaging, payment, etc).

Flyweight

  • Reduces the memory footprint of a program by sharing common parts of objects.
  • Stores only intrinsic state. Extrinsic state is passed as parameters.
  • Suitable for huge numbers of similar objects.
  • Example: Browser caching images by sharing common parts.

Studying That Suits You

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

Quiz Team

Related Documents

More Like This

Adapter Pattern: Converting Interfaces
6 questions
Structural Design Patterns: Adapter
55 questions
Use Quizgecko on...
Browser
Browser