0% found this document useful (0 votes)
4 views

Lec4 designPattern

The document discusses various design patterns in software development, including Encapsulation, Facade, and Flyweight, highlighting their purposes, benefits, and applications. It covers key concepts such as memory usage, error handling, object creation, and the importance of minimizing dependencies. The document also emphasizes the significance of design patterns in improving maintainability and reusability in programming languages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lec4 designPattern

The document discusses various design patterns in software development, including Encapsulation, Facade, and Flyweight, highlighting their purposes, benefits, and applications. It covers key concepts such as memory usage, error handling, object creation, and the importance of minimizing dependencies. The document also emphasizes the significance of design patterns in improving maintainability and reusability in programming languages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

1.

Which design pattern addresses the problem of exposed fields being directly manipulated from
outside, leading to undesirable dependencies?
a) Subclassing
b) Encapsulation
c) Iteration
d) Exceptions
2. What is the solution provided by the Encapsulation pattern?
a) Permitting only stylized access to the object
b) Allowing direct manipulation of exposed fields
c) Encouraging the use of inheritance
d) Avoiding exceptions entirely
3. What problem does the Exception pattern aim to solve?
a) Code cluttered with error handling
b) Overuse of encapsulation
c) Lack of inheritance in code design
d) Inefficient iteration techniques
4. Which programming language feature is commonly used for throwing and catching
exceptions?
a) Subclassing
b) Encapsulation
c) Iteration
d) Exceptions
5. Creational patterns primarily concern which aspect of object-oriented programming?
a) Object destruction
b) Object creation
c) Object composition
d) Object communication
6. Structural patterns are primarily concerned with:
a) Object creation
b) Object destruction
c) Integration and composition of classes and objects
d) Class inheritance
7. What aspect of programming languages are moving towards design according to the provided
context?
a) Syntax
b) Paradigms
c) Features
d) Performance
8. What is the addressing Quality Attribute primarily concerned with?
a) Efficiency
b) Flexibility
c) Modifiability
d) Performance
9. Which property do design patterns provide for better reusability?
a) Increased redundancy
b) More specialized code
c) More general code
d) Complex implementations
10. Redundant code elimination primarily contributes to which aspect of software quality?
a) Performance
b) Maintainability
c) Flexibility
d) Extensibility
11. Which pattern primarily addresses the problem of cluttered error handling code?
a) Encapsulation
b) Subclassing
c) Iteration
d) Exceptions
12. In the context of programming languages, what are many patterns being implemented for?
a) Enhancing performance
b) Improving maintainability
c) Optimizing memory usage
d) Simplifying syntax
13. Which pattern category concerns with class or object communication?
a) Creational Patterns
b) Structural Patterns
c) Behavioral Patterns
d) Design Patterns
14. What is the primary aim of the Exception pattern?
a) Reducing code complexity
b) Enhancing encapsulation
c) Centralizing error handling
d) Promoting subclassing
15. Which quality attribute does reusability primarily contribute to?
a) Flexibility
b) Maintainability
c) Performance
d) Extensibility
16. What does the Encapsulation pattern aim to hide?
a) Object creation process
b) Internal implementation details
c) Class hierarchy
d) Error handling logic
17. Which pattern category concerns with the process of object creation?
a) Structural Patterns
b) Behavioral Patterns
c) Creational Patterns
d) Design Patterns
18. What aspect of programming languages are moving towards design according to the provided
context?
a) Language syntax
b) Compiler optimizations
c) Standard libraries
d) Design patterns
19. What is the primary concern of structural patterns?
a) Object creation
b) Object destruction
c) Integration and composition of classes and objects
d) Object communication
20. Which programming language feature is primarily used to manage object creation and
initialization?
a) Encapsulation
b) Inheritance
c) Iteration
d) Constructor methods

1. b) Encapsulation
2. a) Permitting only stylized access to the object
3. a) Code cluttered with error handling
4. d) Exceptions
5. b) Object creation
6. c) Integration and composition of classes and objects
7. c) Features
8. c) Modifiability
9. c) More general code
10. b) Maintainability
11. d) Exceptions
12. b) Improving maintainability
13. c) Behavioral Patterns
14. c) Centralizing error handling
15. b) Maintainability
16. b) Internal implementation details
17. c) Creational Patterns
18. d) Design patterns
19. c) Integration and composition of classes and objects
20. d) Constructor methods

Facade
1. What is the primary purpose of the Facade Design Pattern?
a) To complicate interactions with a complex subsystem
b) To provide a unified and straightforward interface to a complex subsystem
c) To increase dependencies on the subsystem
d) To conceal the existence of a subsystem
2. How does the Facade pattern improve the readability and usability of a software library?
a) By introducing complexity to the underlying subsystem
b) By presenting a simplified API to the client
c) By tightly coupling the client with the subsystem
d) By adding more interdependent classes to the subsystem
3. What role does the facade play in the Facade pattern?
a) It adds complexity to the subsystem
b) It simplifies interactions with the subsystem
c) It directly exposes the intricacies of the subsystem
d) It increases the dependencies between classes in the subsystem
4. When might developers choose to use the Facade pattern?
a) When the system is simple and has few interdependent classes
b) When the system lacks accessible source code
c) When the system is straightforward and easy to understand
d) When the system does not require any external interfaces
5. What problem does the Facade pattern solve?
a) Tight coupling between classes in a subsystem
b) Lack of complexity in a subsystem
c) Lack of dependencies between classes in a subsystem
d) Difficulty in using a complex subsystem directly
6. How does the Facade pattern simplify interactions with a complex subsystem?
a) By increasing the number of interfaces in the subsystem
b) By delegating to the subsystem's interfaces through a simplified interface
c) By concealing the existence of the subsystem
d) By introducing additional complexity to the client code
7. What additional functionality may a facade object perform in the Facade pattern?
a) It may add complexity to the subsystem
b) It may decrease dependencies on the subsystem
c) It may forward requests to the subsystem without any modifications
d) It may perform operations before or after forwarding requests to the subsystem
8. How does the Facade pattern minimize dependencies on the subsystem?
a) By tightly coupling the client with the subsystem
b) By introducing more interdependent classes in the subsystem
c) By providing a unified interface that shields the client from the subsystem's complexity
d) By increasing the number of direct interactions between the client and the subsystem
9. What analogy best describes the role of the facade in the Facade pattern?
a) A mask hiding the face of the subsystem
b) A window providing a view into the subsystem
c) A door allowing access to the subsystem
d) A bridge connecting the client to the subsystem
10. How does the Facade pattern serve as a starting point for refactoring monolithic systems?
a) By introducing more complexity to the system
b) By tightly coupling the subsystem with the client
c) By providing a context-specific interface for generic functionality
d) By simplifying interactions with a complex subsystem
11. Which statement accurately describes the Facade pattern's approach to providing a unified interface?
a) It exposes all the intricacies of the subsystem to the client.
b) It hides the existence of the subsystem from the client.
c) It presents a simplified API that shields the client from the complexity of the subsystem.
d) It tightly couples the client with the subsystem, increasing dependencies.
12. How does the Facade pattern contribute to improving the maintainability of software?
a) By introducing more interdependent classes in the subsystem
b) By providing a simplified API that is easier to understand and use
c) By complicating interactions with the subsystem
d) By increasing the dependencies between classes in the subsystem
13. What is a key characteristic of the Facade pattern?
a) It increases dependencies on the subsystem.
b) It tightly couples the client with the subsystem.
c) It provides a unified and straightforward interface to a complex subsystem.
d) It exposes all the intricacies of the subsystem to the client.
14. How does the Facade pattern affect the coupling between the client and the subsystem?
a) It increases coupling by exposing all the subsystem's intricacies.
b) It decreases coupling by providing a simplified interface to the subsystem.
c) It has no effect on coupling.
d) It increases coupling by introducing additional complexity
15. What role does the facade play in the Facade pattern's approach to simplifying interactions?
a) It adds complexity to the subsystem.
b) It conceals the existence of the subsystem from the client.
c) It provides a simplified interface to the subsystem's functionality.
d) It increases the dependencies between classes in the subsystem.
1. b) To provide a unified and straightforward interface to a complex subsystem
2. b) By presenting a simplified API to the client
3. b) It simplifies interactions with the subsystem
4. b) When the system lacks accessible source code
5. d) Difficulty in using a complex subsystem directly
6. b) By delegating to the subsystem's interfaces through a simplified interface
7. d) It may perform operations before or after forwarding requests to the subsystem
8. c) By providing a unified interface that shields the client from the subsystem's complexity
9. a) A mask hiding the face of the subsystem
10. d) By simplifying interactions with a complex subsystem
11. c) It presents a simplified API that shields the client from the complexity of the subsystem.
12. b) By providing a simplified API that is easier to understand and use
13. c) It provides a unified and straightforward interface to a complex subsystem.
14. b) It decreases coupling by providing a simplified interface to the subsystem.
15. c) It provides a simplified interface to the subsystem's functionality.

Flyweight
1. What is the primary purpose of the Flyweight pattern?
a) To maximize memory usage
b) To minimize memory usage
c) To duplicate data for each object
d) To separate intrinsic state from extrinsic state
2. In the Flyweight pattern, what is the intrinsic state?
a) Variant and context-dependent data
b) Context-independent and shareable data
c) Data that varies from object to object
d) Data shared among all instances of an object
3. Which example demonstrates the use of the Flyweight pattern?
a) Video game graphics rendering
b) Text editors like LibreOffice Writer
c) Database management systems
d) Operating system kernel design
4. How does the Flyweight pattern reduce memory usage?
a) By duplicating data for each object
b) By minimizing the number of physically created objects
c) By separating intrinsic state from extrinsic state
d) By increasing memory overhead
5. What is an example of extrinsic state in a word processor?
a) The font outline of a character
b) The position of a character in a text document
c) The formatting data of a character
d) The metrics of a character
6. Which benefit is NOT associated with the Flyweight pattern?
a) Reduced memory usage
b) Improved reusability
c) Increased complexity
d) Efficient sharing of objects
7. In the Flyweight pattern, what kind of data is the extrinsic state?
a) Context-independent
b) Shareable
c) Variant
d) Invariant
8. What does the Flyweight pattern aim to minimize?
a) Memory usage
b) CPU usage
c) Execution time
d) Network latency
9. Which state of an object is context-independent and shareable?
a) Intrinsic state
b) Extrinsic state
c) Variant state
d) Context-dependent state
10. What type of objects benefit most from the Flyweight pattern?
a) Objects with highly variant states
b) Objects with low memory requirements
c) Objects with complex data structures
d) Objects with shared common elements
11. Which scenario is NOT suitable for applying the Flyweight pattern?
a) Managing large amounts of text data in a word processor
b) Rendering graphics in a video game
c) Storing individual user preferences in a database
d) Handling network packets in a communication protocol
12. What does the Flyweight pattern share among similar objects?
a) Extrinsic state
b) Context-dependent data
c) Common data structures
d) Invariant data
14. In the Flyweight pattern, what does reusability refer to?
a) The ability to reuse objects with different intrinsic states
b) The ability to reuse objects with different extrinsic states
c) The ability to reuse Flyweight objects and pass in extrinsic state
d) The ability to reuse Flyweight objects without considering state
15. What kind of objects does the Flyweight pattern support efficiently?
a) Large and complex objects
b) Small and fine-grained objects
c) Objects with high memory usage
d) Objects with low memory usage
16. How does the Flyweight pattern support large numbers of fine-grained objects?
a) By duplicating data for each object
b) By minimizing the number of physically created objects
c) By increasing memory overhead
d) By separating intrinsic state from extrinsic state
17. What distinguishes intrinsic state from extrinsic state in the Flyweight pattern?
a) Intrinsic state is variant, while extrinsic state is invariant.
b) Intrinsic state is context-dependent, while extrinsic state is context-
independent.
c) Intrinsic state is shared among objects, while extrinsic state varies per object.
d) Intrinsic state is unshareable, while extrinsic state is shareable.
18. What does the Flyweight pattern achieve by separating intrinsic state from
extrinsic state?
a) It increases memory usage.
b) It minimizes memory usage.
c) It reduces object reusability.
d) It complicates object creation.
19. Which characteristic does NOT apply to intrinsic state in the Flyweight pattern?
a) Context-dependent
b) Invariant
c) Shareable
d) Context-independent
20. What role does the Flyweight pattern play in managing memory efficiently?
a) It duplicates data for each object.
b) It increases memory usage.
c) It shares common data structures among similar objects.
d) It separates intrinsic state from extrinsic state.
21. Which statement best describes the primary purpose of the Flyweight pattern?
a) To maximize memory usage efficiency
b) To minimize memory usage by duplicating data for each object
c) To manage shared data structures among similar objects
d) To eliminate the need for intrinsic and extrinsic state management
22. In the context of the Flyweight pattern, what is an example of shared data?
a) Duplicated data for each object
b) Variant and context-dependent data
c) Common data structures among similar objects
d) Unshareable data unique to each object
23. How does the Flyweight pattern manage memory efficiently in a word
processor?
a) By embedding all data for each character individually
b) By sharing common data structures among instances of the same character
c) By duplicating glyph objects for each character instance
d) By separating intrinsic state from extrinsic state completely
24. What type of data is considered intrinsic state in the Flyweight pattern?
a) Variant, context-dependent, and unshareable
b) Invariant, context-independent, and shareable
c) Variant, context-independent, and shareable
d) Invariant, context-dependent, and unshareable
25. Which scenario illustrates the use of the Flyweight pattern effectively?
a) Managing a small number of complex objects with unique attributes
b) Handling individual user preferences in a web browser
c) Processing large volumes of text data with repeated elements
d) Rendering high-resolution images in a graphics application
26. In the Flyweight pattern, what role does the extrinsic state play?
a) It determines the shared data structures among objects.
b) It defines the context-independent properties of an object.
c) It specifies the variant and context-dependent data unique to each object.
d) It manages the memory overhead associated with shared data structures
28. Which statement accurately describes the management of shared data in the
Flyweight pattern?
a) Each object stores its own copy of shared data structures.
b) Common data structures are shared among all instances of an object.
c) Shared data is duplicated for each object to ensure independence.
d) Shared data is stored externally and accessed when needed.
30. How does the Flyweight pattern contribute to reducing memory overhead?
a) By increasing memory usage through duplication of data
b) By separating intrinsic state from extrinsic state completely
c) By efficiently sharing common data structures among similar objects
d) By minimizing the reuse of Flyweight objects in the application
31. How does the Flyweight pattern contribute to reducing memory usage?
a) By increasing memory allocation for each object
b) By duplicating intrinsic state for each object
c) By efficiently storing intrinsic state and minimizing object creation
d) By storing both intrinsic and extrinsic state separately for each object
32. What advantage does reusability offer in the context of the Flyweight pattern?
a) It increases the number of physically created objects.
b) It reduces the sharing of common data structures among objects.
c) It allows clients to reuse Flyweight objects and customize extrinsic state.
d) It limits the flexibility of using Flyweight objects in different contexts.
33. Which statement accurately describes the benefit of reduced memory usage in
the Flyweight pattern?
a) It increases the overall memory footprint of the application.
b) It improves performance by minimizing the sharing of common data structures.
c) It optimizes memory allocation by efficiently storing intrinsic state.
d) It decreases the efficiency of managing shared data among objects.
34. What role does reusability play in minimizing the number of physically created
objects in the Flyweight pattern?
a) It encourages the creation of new objects for each unique scenario.
b) It allows clients to customize intrinsic state for each object instance.
c) It enables the reuse of Flyweight objects with different extrinsic states.
d) It restricts the sharing of common data structures among similar objects.

1. b) To minimize memory usage


2. b) Context-independent and shareable data
3. b) Text editors like LibreOffice Writer
4. b) By minimizing the number of physically created objects
5. b) The position of a character in a text document
6. c) Increased complexity
7. c) Variant
8. a) Memory usage
9. a) Intrinsic state
10. d) Objects with shared common elements
11. c) Storing individual user preferences in a database
12. c) Common data structures
14. c) The ability to reuse Flyweight objects and pass in extrinsic state
15. b) Small and fine-grained objects
16. b) By minimizing the number of physically created objects
17. c) Intrinsic state is shared among objects, while extrinsic state varies per object.
18. b) It minimizes memory usage.
19. a) Context-dependent
20. c) It shares common data structures among similar objects.
21. c) To manage shared data structures among similar objects
22. c) Common data structures among similar objects
23. b) By sharing common data structures among instances of the same character
24. b) Invariant, context-independent, and shareable
25. c) Processing large volumes of text data with repeated elements
26. c) It specifies the variant and context-dependent data unique to each object.
28. b) Common data structures are shared among all instances of an object.
30. c) By efficiently sharing common data structures among similar objects
31. c) By efficiently storing intrinsic state and minimizing object creation
32. c) It allows clients to reuse Flyweight objects and customize extrinsic state.
33. c) It optimizes memory allocation by efficiently storing intrinsic state.
34. c) It enables the reuse of Flyweight objects with different extrinsic states.

Chain of Responsibility
1. What is the primary purpose of the Chain of Responsibility pattern?
a) To tightly couple senders and receivers
b) To allow handlers to bypass requests
c) To decouple senders and receivers
d) To limit the flexibility and extensibility of the code
2. Which participant in the Chain of Responsibility pattern defines the common
methods for handling requests?
a) Sender
b) Receiver
c) Handler
d) ConcreteHandler
3. What role does the ConcreteHandler play in the Chain of Responsibility pattern?
a) It defines the common methods for handling requests.
b) It encapsulates the handling logic within the handlers.
c) It sends requests to the first handler in the chain.
d) It decides whether to handle a request or pass it to the next handler.
4. How does the Chain of Responsibility pattern work when processing requests?
a) Handlers simultaneously process all requests in the chain.
b) Each handler directly communicates with the client to process requests.
c) Handlers sequentially pass requests along the chain until one handles it or the
end is reached.
d) Handlers process requests independently without passing them to other
handlers.
5. Which benefit does the Chain of Responsibility pattern provide in terms of code
organization?
a) It introduces tight coupling between senders and receivers.
b) It promotes single responsibility within each handler.
c) It limits the flexibility and extensibility of the code.
d) It increases complexity by adding multiple layers of abstraction.
6. What aspect of the Chain of Responsibility pattern promotes flexibility and
extensibility?
a) Direct communication between handlers
b) Encapsulation of handling logic within the handlers
c) Ease of adding or removing handlers without affecting client code
d) Sequential processing of requests without passing them along the chain
7. In the context of the Chain of Responsibility pattern, what does "single
responsibility" refer to?
a) Each handler focuses on handling multiple types of requests.
b) Each handler has a single method for processing requests.
c) Each handler specializes in handling a specific type of request or condition.
d) Each handler communicates directly with the client without involving other
handlers.
8. How does the client interact with the Chain of Responsibility pattern?
a) By directly invoking methods on the ConcreteHandler objects
b) By passing requests to the first handler in the chain
c) By creating instances of the Handler interface
d) By implementing the handling logic within the client code
9. What is the benefit of decoupling senders and receivers in the Chain of
Responsibility pattern?
a) It increases code complexity and maintenance overhead.
b) It allows senders to directly communicate with specific receivers.
c) It promotes flexibility by allowing handlers to process requests independently.
d) It restricts the flow of requests within the chain of handlers.
10. How does the Chain of Responsibility pattern handle requests when a handler
cannot process them?
a) The handler directly processes the request.
b) The handler passes the request to the previous handler in the chain.
c) The handler passes the request to the next handler in the chain.
d) The handler terminates the chain and notifies the client.
11. Which participant in the Chain of Responsibility pattern specializes in handling
specific types of requests?
a) Sender
b) Receiver
c) Handler
d) ConcreteHandler
12. What analogy is used to describe the behavior of the Chain of Responsibility
pattern?
a) Sharing news at a banana party
b) Passing a baton in a relay race
c) Broadcasting messages on a radio station
d) Building a chain link by link
13. How does the Chain of Responsibility pattern contribute to promoting single
responsibility?
a) By allowing handlers to process multiple types of requests
b) By encapsulating handling logic within each handler
c) By tightly coupling senders and receivers
d) By bypassing requests that handlers cannot handle
14. Which key participant in the Chain of Responsibility pattern defines the structure
for handling requests?
a) ConcreteHandler
b) Handler
c) Sender
d) Receiver
15. What does the client need to know about the handlers in the Chain of
Responsibility pattern?
a) The specific order of the handlers in the chain
b) The concrete implementations of the handlers
c) The common methods defined by the Handler interface or abstract class
d) The direct communication channels between handlers
16. What does the term "chain" represent in the Chain of Responsibility pattern?
a) A linear sequence of handlers connected by direct communication links
b) A hierarchical structure of handlers organized based on their responsibilities
c) A circular arrangement of handlers where each handler points to the next
d) A linear sequence of handlers where each handler passes requests to the next
in line
17. How does the Chain of Responsibility pattern facilitate the addition or removal of
handlers?
a) By tightly coupling handlers to specific types of requests
b) By encapsulating handling logic within the client code
c) By defining a common interface for all handlers and allowing dynamic
modification of the chain
d) By restricting access to handlers and preventing changes to the chain structure
18. What analogy describes the sequential processing of requests in the Chain of
Responsibility pattern?
a) A relay race where each runner passes a baton to the next
b) A web of interconnected nodes where messages are broadcasted
c) A chain link by link where each link contributes to the overall strength
d) A series of dominos falling one after another when triggered
19. How does the Chain of Responsibility pattern handle requests at the end of the
chain?
a) By passing them back to the client for further processing
b) By terminating the chain and discarding the requests
c) By redirecting them to the first handler in the chain
d) By handling them within a default handler designated for such cases
20. What analogy illustrates the flow of requests in the Chain of Responsibility
pattern?
a) Passing a baton in a relay race
b) Broadcasting messages on a radio station
c) Building a chain link by link
d) Sharing news at a banana party
Sure, here are the answers to the provided hard-level multiple-choice questions:
1. c) To decouple senders and receivers
2. c) Handler
3. d) It decides whether to handle a request or pass it to the next handler.
4. c) Handlers sequentially pass requests along the chain until one handles it or the
end is reached.
5. b) It promotes single responsibility within each handler.
6. c) Ease of adding or removing handlers without affecting client code
7. c) Each handler specializes in handling a specific type of request or condition.
8. b) By passing requests to the first handler in the chain
9. c) It promotes flexibility by allowing handlers to process requests independently.
10. c) The handler passes the request to the next handler in the chain.
11. d) ConcreteHandler
12. a) Sharing news at a banana party
13. b) By encapsulating handling logic within each handler
14. b) Handler
15. c) The common methods defined by the Handler interface or abstract class
16. d) A linear sequence of handlers where each handler passes requests to the
next in line
17. c) By defining a common interface for all handlers and allowing dynamic
modification of the chain
18. a) A relay race where each runner passes a baton to the next
19. b) By terminating the chain and discarding the requests
20. a) Passing a baton in a relay race

Memento
1. What is the primary purpose of the Memento pattern?
a) To manage the creation and destruction of objects
b) To save checkpoints in an application and restore an object to those
checkpoints
c) To control access to objects and their state
d) To define algorithms in a family of related algorithms
2. Which component in the Memento pattern is responsible for creating and
managing an object's state?
a) Originator
b) Memento
c) Caretaker
d) Client
3. What role does the Caretaker play in the Memento pattern?
a) It creates Memento objects to store snapshots of an object's state.
b) It retrieves Memento objects from the Originator to save or restore the object's
state.
c) It requests the Originator to perform operations such as "save state" or "restore
state."
d) It interacts with the Client to achieve specific functionality.
4. How does the Memento prevent direct modification of the object's state?
a) By encapsulating the object's state within the Memento object
b) By restricting access to the object's state only to the Caretaker
c) By encrypting the object's state before storing it
d) By providing public access to the object's state for modification
5. What is the role of the Client in the Memento pattern?
a) To create and manage Memento objects
b) To request the Originator to save or restore the object's state
c) To interact with the Originator and Caretaker to achieve specific functionality
d) To define and implement the internal state of an object
6. How does the Originator handle a request to save the state in the Memento
pattern?
a) By directly modifying the object's state
b) By creating a Memento, capturing its current state and returning it to the Client
or Caretaker
c) By encrypting the object's state before saving it
d) By passing the request to the Caretaker for further processing
7. What is the primary benefit of using the Memento pattern in an application?
a) To improve performance by reducing memory overhead
b) To implement complex algorithms for data processing
c) To enable undo and redo functionality by saving and restoring object states
d) To enforce strict encapsulation of object state within the Originator
8. How does the Memento pattern facilitate the implementation of undo and redo
operations?
a) By restricting access to the object's state
b) By allowing the Client to directly modify the object's state
c) By storing snapshots of the object's state in Memento objects
d) By encrypting the object's state for secure storage
9. In the context of the Memento pattern, what is state preservation?
a) The ability to encrypt the object's state for secure storage
b) The capability to preserve the internal state of an object without exposing it to
other objects
c) The process of modifying the object's state directly
d) The practice of limiting access to the object's state only to the Originator
10. How does the Memento pattern contribute to recovery from errors or failures?
a) By preventing the occurrence of errors or failures in the first place
b) By storing snapshots of the object's state, allowing it to be restored after an
error or failure
c) By encrypting the object's state to prevent unauthorized access
d) By restricting access to the object's state, ensuring its integrity at all times
11. Which functionality does the Memento pattern provide in terms of history
tracking and auditing?
a) It enables real-time monitoring of object state changes
b) It provides a way to track and audit changes in an object's state over time
c) It automatically logs all interactions between objects
d) It encrypts the object's state to ensure data integrity
12. How does the Memento pattern collaborate with the Command pattern?
a) By directly modifying the object's state
b) By storing snapshots of the object's state for future reference
c) By allowing commands to be executed without changing the object's state
d) By using Memento objects to store the state before executing a command and
restoring it if necessary
13. What additional functionality does the Memento pattern provide when used in
collaboration with the Command pattern?
a) It enables commands to directly modify the object's state
b) It allows for advanced undo and redo functionality by storing multiple
snapshots of the object's state
c) It encrypts the object's state to prevent unauthorized access
d) It restricts access to the object's state, ensuring its integrity at all times
14. How can the Memento pattern be used for snapshotting and serialization?
a) By encrypting the object's state before storing it
b) By allowing the object's state to be stored in a file or database for persistence
or transfer
c) By limiting access to the object's state only to the Caretaker
d) By storing the object's state in Memento objects for secure storage
15. What analogy is used to describe the behavior of the Memento pattern?
a) Writing and reading from a journal
b) Locking and unlocking a door
c) Taking a photograph and developing it
d) Building a time machine to revert to previous states
16. How does the Memento pattern handle requests to restore the object's state?
a) By directly modifying the object's state
b) By creating a new object with the restored state
c) By retrieving the desired Memento containing the state to restore
d) By encrypting the object's state before restoring it
17. Which component in the Memento pattern interacts directly with the Originator
to perform operations?
a) Client
b) Caretaker
c) Memento
d) Originator
18. What role does the Memento play in the Memento pattern?
a) It creates and manages the object's state
b) It stores snapshots of the object's state
c) It interacts with the Client to achieve specific functionality
d) It encapsulates the handling logic within each handler
19. In the Memento pattern, how does the Originator interact with the Caretaker?
a) By directly modifying the object's state
b) By passing requests to the Client for further processing
c) By creating and managing Memento objects
d) By providing methods to save and restore the object's state
20. Which component in the Memento pattern is responsible for managing Memento
objects?
a) Originator
b) Caretaker
c) Client
d) Memento

1. b) To save checkpoints in an application and restore an object to those


checkpoints
2. a) Originator
3. b) It retrieves Memento objects from the Originator to save or restore the object's
state.
4. a) By encapsulating the object's state within the Memento object
5. c) To interact with the Originator and Caretaker to achieve specific functionality
6. b) By creating a Memento capturing its current state and returning it to the Client
or Caretaker
7. c) To enable undo and redo functionality by saving and restoring object states
8. c) By storing snapshots of the object's state in Memento objects
9. b) The capability to preserve the internal state of an object without exposing it to
other objects
10. b) By storing snapshots of the object's state, allowing it to be restored after an
error or failure
11. b) It provides a way to track and audit changes in an object's state over time
12. d) By using Memento objects to store the state before executing a command
and restoring it if necessary
13. b) It allows for advanced undo and redo functionality by storing multiple
snapshots of the object's state
14. b) By allowing the object's state to be stored in a file or database for persistence
or transfer
15. a) Writing and reading from a journal
16. c) By retrieving the desired Memento containing the state to restore
17. b) Caretaker
18. b) It stores snapshots of the object's state
19. d) By providing methods to save and restore the object's state
20. b) Caretaker

Observer
1. What primary challenge does the Observer design pattern address?
a) Managing one-to-one dependencies between objects
b) Dealing with tight coupling between subject and observers
c) Defining a one-to-many dependency between objects
d) Ensuring uniformity in object behavior
2. What is the responsibility of the Subject in the Observer pattern?
a) Update its state without notifying others
b) Maintain a list of observers and notify them of state changes
c) Register/unregister with observers
d) Determine the behavior of the observers
3. How does the Observer pattern achieve loose coupling between subject and
observers?
a) By directly modifying the observer's state
b) By tightly integrating subject and observer logic
c) By defining a clear interface for communication
d) By restricting the number of observers
4. Which real-world analogy best represents the Observer pattern?
a) A teacher updating individual students about class changes
b) A weather station notifying various displays about weather changes
c) A manager assigning tasks to team members
d) A newspaper printing articles for its readers
5. What benefit does the Observer pattern offer in terms of flexibility?
a) Objects become harder to implement and test
b) Automatic updates for observers
c) Decoupling of subject and observers
d) Limited scalability due to fixed observer list
6. What is the role of the Observer in the Observer pattern?
a) Maintain a list of subjects
b) Notify the subject of state changes
c) Register/unregister with the subject and synchronize state
d) Update its state without notifying others
7. In the Observer pattern, how does the subject communicate changes to its
observers?
a) By directly modifying the observer's state
b) By calling the observer's `notify()` method
c) By sending emails to all observers
d) By invoking the observer's `update()` method
8. What advantage does the Observer pattern provide in terms of dynamic updates?
a) Tight coupling between subject and observers
b) Objects become harder to implement and test
c) Automatic updates for observers
d) Limited scalability due to fixed observer list
9. Which scenario best demonstrates the need for the Observer pattern?
a) A single object controlling the behavior of multiple others
b) Objects that do not interact with each other
c) Objects that require tight coupling for efficient communication
d) Objects that need to be completely independent of each other
10. In the context of the Observer pattern, what does "synchronizing its state with
the subject’s state" mean for observers?
a) Observers directly modify the subject's state
b) Observers maintain their state independent of the subject
c) Observers update their state to reflect changes in the subject's state
d) Observers ignore changes in the subject's state

1. c) Defining a one-to-many dependency between objects


2. b) Maintain a list of observers and notify them of state changes
3. c) By defining a clear interface for communication
4. b) A weather station notifying various displays about weather changes
5. c) Decoupling of subject and observers
6. c) Register/unregister with the subject and synchronize state
7. d) By invoking the observer's `update()` method
8. c) Automatic updates for observers
9. a) A single object controlling the behavior of multiple others
10. c) Observers update their state to reflect changes in the subject's state

Adapter
1. What problem does the Adapter design pattern address?
a) Data manipulation
b) Interface incompatibility
c) Algorithm optimization
d) Memory management
2. In the Adapter pattern, what does the Target Interface represent?
a) The existing class with an incompatible interface
b) The interface expected by the client
c) The bridge between incompatible interfaces
d) The code that uses the target interface to interact with objects
3. Which component of the Adapter pattern represents the existing class with an
incompatible interface?
a) Adaptee
b) Adapter
c) Target Interface
d) Client
4. What is the role of the Adapter in the Adapter pattern?
a) Defines the interface expected by the client
b) Implements the target interface and internally uses an instance of the adaptee
c) Acts as a bridge, adapting the interface of the adaptee to match the target
interface
d) Represents the code that uses the target interface to interact with objects
5. In the Adapter pattern, what is the purpose of the Client?
a) To represent the existing class with an incompatible interface
b) To act as a bridge between incompatible interfaces
c) To implement the target interface
d) To use the target interface to interact with objects
7. How does the Adapter pattern bridge the gap between incompatible interfaces?
a) By defining a clear interface for communication
b) By restricting the number of adapters
c) By implementing the same interface in both classes
d) By directly modifying the adoptee’s interface
9. What role does the Target Interface play in the Adapter pattern?
a) It represents the existing class with an incompatible interface
b) It defines the interface expected by the client
c) It adapts the interface of the adaptee to match the target interface
d) It implements the target interface and internally uses an instance of the adapte
10. In the provided context, what does the Adapter (Non software example)
represent?
a) Converting messages between English and French speakers
b) Representing the existing class with an incompatible interface
c) Bridging the gap between incompatible interfaces
d) Connecting two friends with different language abilities
13. How does the Adapter pattern facilitate integration of legacy systems?
a) By completely replacing existing systems
b) By modifying existing interfaces directly
c) By providing a bridge between existing and new systems
d) By isolating legacy systems from new developments
14. What challenge does the Adapter pattern help overcome when integrating third-
party libraries?
a) Tight coupling between client code and the library
b) Lack of documentation for the library's interfaces
c) Incompatibility between the library's interfaces and client requirements
d) Difficulty in maintaining version compatibility
15. What advantage does the Adapter pattern offer in terms of system scalability?
a) It restricts the flexibility to adapt interfaces
b) It limits the number of adapters that can be added
c) It allows adding new adapters without modifying existing code
d) It increases the complexity of the system, reducing scalability

Answers:
1. b) Interface incompatibility
2. b) The interface expected by the client
3. a) Adaptee
4. c) Acts as a bridge, adapting the interface of the adaptee to match the target
interface
5. d) To use the target interface to interact with objects
6. a) Translating messages between English and French speakers
7. d) By directly modifying the adaptee's interface
8. b) Adapter
9. b) It defines the interface expected by the client
10. c) Bridging the gap between incompatible interfaces
11. b) Two objects with incompatible interfaces needing to work together
12. c) It enhances code modularity, promoting reusability
13. c) By providing a bridge between existing and new systems
14. c) Incompatibility between the library's interfaces and client requirements
15. c) It allows adding new adapters without modifying existing code

Singleton
1. What is the primary characteristic of the Singleton design pattern?
a) It allows multiple instances to be created per container
b) It ensures that only one instance is created per container
c) It provides a global point of access to multiple instances
d) It restricts access to instances from other containers
2. Which programming language feature makes implementing the Module-level
Singleton easy in Python?
a) Classes
b) Modules
c) Functions
d) Decorators
3. What is the advantage of using Module-level Singleton in Python?
a) It allows for more flexible instance creation
b) It ensures that only one instance is created per module
c) It restricts access to the singleton instance
d) It requires less code to implement compared to other methods
4. How does the Classic Singleton differ from the Module-level Singleton?
a) Classic Singleton allows for multiple instances to be created
b) Classic Singleton creates an instance only if none exists
c) Classic Singleton restricts access to the singleton instance
d) Classic Singleton does not rely on module-level behavior
5. What is the purpose of the Borg Singleton pattern?
a) To restrict access to the singleton instance
b) To create an instance only if none exists
c) To allow state sharing for different instances while maintaining separate
instances
d) To enforce module-level behavior in Python
6. Which Singleton implementation ensures that data is shared among different
instances?
a) Module-level Singleton
b) Classic Singleton
c) Borg Singleton
d) Both a and b
9. Which Singleton pattern is suitable for scenarios where separate instances need
to share state?
a) Module-level Singleton
b) Classic Singleton
c) Borg Singleton
d) Both b and c
10. Which Singleton pattern implementation is the most commonly used in Python?
a) Module-level Singleton
b) Classic Singleton
c) Borg Singleton
d) Decorator Singleton
11. How does the Borg Singleton pattern achieve state sharing among different
instances?
a) By creating a new instance for each request
b) By ensuring that only one instance is created per container
c) By sharing the same internal state among all instances
d) By restricting access to the singleton instance
12. In which scenario would the Module-level Singleton be preferred over the Classic
Singleton?
a) When lazy initialization of the singleton instance is desired
b) When separate instances need to share state
c) When simplicity and ease of implementation are prioritized
d) When strict control over instance creation is required
13. What is the primary purpose of the Singleton design pattern?
a) To ensure that only one instance is created per container
b) To restrict access to the singleton instance
c) To enforce module-level behavior in Python
d) To allow for lazy initialization of objects
14. Which Singleton implementation would be most suitable for multithreaded
environments?
a) Module-level Singleton
b) Classic Singleton
c) Borg Singleton
d) Decorator Singleton
15. How does the Singleton pattern ensure thread safety in multithreaded
environments?
a) By using locks to synchronize access to the singleton instance
b) By restricting access to the singleton instance to a single thread
c) By creating separate instances for each thread
d) By preventing lazy initialization of the singleton instance

Answers:
1. b) It ensures that only one instance is created per container
2. b) Modules
3. b) It ensures that only one instance is created per module
4. b) Classic Singleton creates an instance only if none exists
5. c) To allow state sharing for different instances while maintaining separate
instances
6. a) Module-level Singleton
7. d) Only if no instance exists; otherwise, it returns the existing instance
8. c) It allows state sharing for different instances while maintaining separate
instances
9. c) Borg Singleton
10. a) Module-level Singleton
11. c) By sharing the same internal state among all instances
12. c) When simplicity and ease of implementation are prioritized
13. a) To ensure that only one instance is created per container
14. b) Classic Singleton
15. a) By using locks to synchronize access to the singleton instance

Builder ---------
1. What is the primary objective of the Builder design pattern?
a) To separate the construction process of a complex object from its
representation
b) To directly construct complex objects without a builder interface
c) To encapsulate the product's construction logic within the client code
d) To provide a single constructor for creating complex objects
2. Which participant in the Builder pattern provides a higher-level interface for
constructing the product?
a) Builder
b) Concrete Builder
c) Director
d) Product
3. What is the role of the Concrete Builder in the Builder pattern?
a) It provides a higher-level interface for constructing the product
b) It defines the steps and operations required to build the product
c) It maintains an instance of the product being built
d) It knows the specific steps and order in which the builder's methods should be
called
4. How does the Builder pattern achieve separation of concerns?
a) By directly exposing the product's construction logic to the client code
b) By isolating the construction logic in the builder, separate from the client code
c) By implementing the product variations within the builder interface
d) By allowing multiple constructors for creating complex objects
5. What is the purpose of the Director in the Builder pattern?
a) To define the steps and operations required to build the product
b) To maintain an instance of the product being built
c) To provide a higher-level interface for constructing the product using the builder
d) To represent the final object that is assembled step by step
6. Which benefit of the Builder pattern allows for better control over the
construction process?
a) Separation of concerns
b) Step-by-step construction
c) Product variations
d) Improved object creation
7. How does the Builder pattern enable the creation of different representations of
the product?
a) By directly exposing the product's construction logic to the client code
b) By providing a clear API for constructing objects
c) By implementing different strategies to build variations of the product within
the builder
d) By using multiple constructors with different arguments
8. Which aspect of the Builder pattern eliminates the need for multiple constructors
or complex constructor arguments?
a) Separation of concerns
b) Step-by-step construction
c) Product variations
d) Improved object creation
9. What does the Product represent in the Builder pattern?
a) The concrete implementation of the builder interface
b) The complex object being constructed by the builder
c) The higher-level interface for constructing the product
d) The specific steps and operations required to build the product
10. In the Builder pattern, what does the Builder interface or class define?
a) The specific steps and order in which the builder's methods should be called
b) The construction logic isolated in the builder
c) The steps and operations required to build the product
d) The instance of the product being built
11. How does the Director know the specific steps and order in which the builder's
methods should be called?
a) It directly implements the steps and operations required to build the product
b) It maintains an instance of the product being built
c) It collaborates with the Concrete Builder to define the construction process
d) It encapsulates the product's construction logic within the client code
12. What does the Concrete Builder maintain in the Builder pattern?
a) An instance of the product being built
b) The specific steps and order in which the builder's methods should be called
c) The construction logic isolated in the builder
d) The higher-level interface for constructing the product using the builder
13. Which benefit of the Builder pattern allows for easier code organization and
maintainability?
a) Separation of concerns
b) Step-by-step construction
c) Product variations
d) Improved object creation
14. How does the Builder pattern ensure flexibility in constructing complex objects?
a) By directly exposing the product's construction logic to the client code
b) By allowing multiple constructors for creating complex objects
c) By providing a clear API for constructing objects step by step
d) By implementing the product variations within the builder interface
15. Which participant in the Builder pattern acts as a bridge, adapting the interface
of the adaptee to match the target interface?
a) Builder
b) Concrete Builder
c) Director
d) Product

Answers:
1. a) To separate the construction process of a complex object from its
representation
2. c) Director
3. c) It maintains an instance of the product being built
4. b) By isolating the construction logic in the builder, separate from the client code
5. c) To provide a higher-level interface for constructing the product using the
builder
6. b) Step-by-step construction
7. c) By implementing different strategies to build variations of the product within
the builder
8. d) Improved object creation
9. b) The complex object being constructed by the builder
10. c) The steps and operations required to build the product
11. c) It collaborates with the Concrete Builder to define the construction process
12. a) An instance of the product being built
13. a) Separation of concerns
14. c) By providing a clear API for constructing objects step by step
15. b) Concrete Builder
Certainly! Here are 15 multiple-choice questions (MCQs) covering various aspects of
the Factory and Command design patterns, with a focus on the provided context:

Factory Design Pattern


1. What is the primary objective of the Factory design pattern?
a) To encapsulate the object creation logic and provide a common interface for
creating different types of objects
b) To encapsulate a request as an object and allow parameterization of clients
with different requests
c) To separate the sender of a request from the object that performs the request
d) To provide an interface for creating objects and allow subclasses to decide
which class to instantiate
2. Which design pattern provides an interface for creating objects but allows
subclasses to decide which class to instantiate?
a) Factory
b) Command
c) Singleton
d) Observer
3. What role does the Factory design pattern play in object creation?
a) It encapsulates the request as an object
b) It encapsulates the object creation logic and provides a common interface
c) It parameterizes clients with different requests
d) It supports undoable operations
4. How does the Factory pattern encapsulate object creation logic?
a) By providing a common interface for creating different types of objects
b) By allowing subclasses to decide which class to instantiate
c) By parameterizing clients with different requests
d) By separating the sender of a request from the object that performs the
request
5. Which scenario is the Factory pattern most suitable for?
a) When encapsulating a request as an object
b) When parameterizing clients with different requests
c) When encapsulating the object creation logic and providing a common interface
d) When separating the sender of a request from the object that performs the
request
6. What is the primary objective of the Command design pattern?
a) To encapsulate the object creation logic and provide a common interface for
creating different types of objects
b) To encapsulate a request as an object and allow parameterization of clients
with different requests
c) To separate the sender of a request from the object that performs the request
d) To provide an interface for creating objects and allow subclasses to decide
which class to instantiate
d) Observer
8. What role does the Command design pattern play in request handling?
a) It encapsulates the request as an object and supports undoable operations
b) It encapsulates the object creation logic and provides a common interface
c) It parameterizes clients with different requests
d) It separates the sender of a request from the object that performs the request
9. How does the Command pattern allow for parameterization of clients with
different requests?
a) By providing a common interface for creating different types of objects
b) By allowing subclasses to decide which class to instantiate
c) By encapsulating the request as an object
d) By separating the sender of a request from the object that performs the
request
10. Which scenario is the Command pattern most suitable for?
a) When encapsulating the object creation logic and providing a common
interface
b) When parameterizing clients with different requests
c) When encapsulating a request as an object
d) When separating the sender of a request from the object that performs the
request
12. How does the Command pattern support undoable operations?
a) By encapsulating the request as an object and allowing for parameterization
b) By encapsulating the object creation logic and providing a common interface
c) By providing an interface for creating objects and allowing subclasses to
decide which class to instantiate
d) By separating the sender of a request from the object that performs the
request
14. Which pattern separates the sender of a request from the object that performs
the request?
a) Factory
b) Command
c) Singleton
d) Observer
15. Which pattern encapsulates the object creation logic and provides a common
interface for creating different types of objects?
a) Factory
b) Command
c) Singleton
d) Observer

Answers:
1. a) To encapsulate the object creation logic and provide a common interface for
creating different types of objects
2. a) Factory
3. b) It encapsulates the object creation logic and provides a common interface
4. a) By providing
a common interface for creating different types of objects
5. c) When encapsulating the object creation logic and providing a common
interface
6. b) To encapsulate a request as an object and allow parameterization of clients
with different requests
7. b) Command
8. a) It encapsulates the request as an object and supports undoable operations
9. c) By encapsulating the request as an object
10. c) When encapsulating a request as an object
11. a) Factory
12. d) By separating the sender of a request from the object that performs the
request
13. c) A request
14. b) Command
15. a) Factory
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
----------------------------------------
1. What is the primary purpose of the Facade design pattern?
a) Simplifying interactions with a complex subsystem
b) Encapsulating object creation logic
c) Handling one-to-many dependencies
d) Managing shared data efficiently
2. Which quality attribute does the Adapter design pattern primarily address?
a) Modifiability
b) Extensibility
c) Reusability
d) Interoperability
3. Which problem does the Memento design pattern primarily solve?
a) Minimizing memory usage
b) Decoupling senders and receivers
c) Capturing and restoring an object's internal state
d) Allowing objects to pass requests along a chain of handlers
4. In the Chain of Responsibility pattern, what is the responsibility of a
ConcreteHandler?
a) It defines the common methods for handling requests.
b) It maintains a list of observers and notifies them of state changes.
c) It decides whether to process a request or pass it along the chain.
d) It encapsulates a request as an object, allowing parameterization and undoable
operations.
5. Which pattern allows programs to efficiently share a large number of objects by
minimizing memory usage?
a) Facade
b) Singleton
c) Flyweight
d) Builder
6. What is the primary role of the Observer pattern?
a) Provide a context-specific interface for generic functionality
b) Decouple objects and automatically update dependents
c) Bridge between incompatible interfaces
d) Encapsulate a request as an object for parameterization
7. Which pattern provides a global point of access to an instance and ensures only
one instance is created per container?
a) Factory
b) Singleton
c) Builder
d) Adapter
8. What is the purpose of the Factory design pattern?
a) Encapsulating a request as an object
b) Simplifying interactions with a complex subsystem
c) Providing an interface for creating objects with subclasses deciding which to
instantiate
d) Allowing step-by-step construction of complex objects
9. Which pattern allows objects to capture and restore their internal state without
violating encapsulation?
a) Memento
b) Chain of Responsibility
c) Command
d) Flyweight
10. What problem does the Command pattern primarily address?
a) Managing shared data efficiently
b) Minimizing memory usage
c) Separating the sender of a request from the object that performs the request
d) Encapsulating object creation logic
11. Which category of patterns concerns the process of object creation?
a) Creational Patterns
b) Structural Patterns
c) Behavioral Patterns
d) Integration Patterns
12. What is the primary benefit of using the Builder pattern?
a) Separation of concerns
b) Improved object creation
c) Dynamic updates
d) Flexibility
13. Which pattern provides a unified and straightforward interface to a set of
interfaces within a complex subsystem?
a) Flyweight
b) Singleton
c) Facade
d) Adapter
14. In the Observer pattern, what is the role of the Subject?
a) It defines the common methods for handling requests.
b) It maintains a list of observers and notifies them of state changes.
c) It encapsulates a request as an object, allowing parameterization and undoable
operations.
d) It provides an interface for creating objects with subclasses deciding which to
instantiate.
15. Which pattern allows objects to efficiently share a large number of fine-grained
objects by minimizing memory usage?
a) Flyweight
b) Adapter
c) Singleton
d) Builder
16. What is the primary responsibility of the Adapter pattern?
a) To bridge between incompatible interfaces
b) To encapsulate a request as an object
c) To simplify interactions with a complex subsystem
d) To provide a global point of access to an instance
17. Which pattern provides a context-specific interface for more generic
functionality and serves as a starting point for refactoring monolithic systems?
a) Facade
b) Observer
c) Chain of Responsibility
d) Singleton
18. Which pattern separates the construction process of a complex object from its
representation?
a) Memento
b) Builder
c) Factory
d) Command
19. What is the primary purpose of the Chain of Responsibility pattern?
a) To improve the readability and usability of a software library
b) To allow objects to efficiently share a large number of objects by minimizing
memory usage
c) To encapsulate a request as an object and separate the sender from the object
that performs the request
d) To allow a request to pass along a chain of handlers until it is handled or
reaches the end of the chain
20. Which pattern is useful for creating a one-to-many dependency between
objects?
a) Adapter
b) Singleton
c) Observer
d) Factory
21. In the Factory pattern, what does the client interact with directly?
a) Concrete Builder
b) Adaptee
c) Target Interface
d) Product
22. What is the primary purpose of the Command pattern?
a) Decoupling senders and receivers
b) Separating the construction process of a complex object from its
representation
c) Providing a context-specific interface for more generic functionality
d) Encapsulating a request as an object and supporting undoable operations
23. Which pattern allows subclasses to decide which class to instantiate?
a) Singleton
b) Adapter
c) Factory
d) Memento
24. Which pattern is useful when dealing with a large number of objects that share
simple repeated elements?
a) Facade
b) Observer
c) Flyweight
d) Command
25. What is the primary benefit of using the Observer pattern?
a) Improved object creation
b) Decoupling objects and automatically updating dependents
c) Separation of concerns
d) Flexibility
26. Which pattern provides a bridge between two incompatible interfaces?
a) Factory
b) Singleton
c) Adapter
d) Command
27. What is the primary role of the Builder pattern?
a) To encapsulate a request as an object and support undoable operations
b) To provide a global point of access to an instance and ensure only one instance
is created per container
c) To allow subclasses to decide which class to instantiate
d) To separate the construction process of a complex object from its
representation
28. In the Memento pattern, what does the Caretaker do?
a) Keeps track of Memento objects and requests them from the Originator to save
or restore the object's state
b) Creates and manages an object's state, creating Memento objects to store
snapshots
c) Registers/unregisters with the subject and synchronizes its state with the
subject's state when notified
d) Requests the Originator to perform operations such as saving or restoring the
object's state
29. What problem does the Facade pattern primarily address?
a) Minimizing memory usage
b) Simplifying interactions with a complex subsystem
c) Decoupling senders and receivers
d) Allowing subclasses to decide which class to instantiate
30. Which pattern allows objects to efficiently share a large number of fine-grained
objects by separating intrinsic and extrinsic state?
a) Chain of Responsibility
b) Observer
c) Memento
d) Flyweight
31. In the Chain of Responsibility pattern, what is the role of the ConcreteHandler?
a) It encapsulates a request as an object, allowing parameterization and
undoable operations
b) It defines the common methods for handling requests
c) It decides whether to process a request or pass it along the chain
d) It maintains a list of observers and notifies them of state changes
32. Which pattern allows objects to capture and restore their internal state without
violating encapsulation?
a) Observer
b) Command
c) Memento
d) Factory
33. What is the primary benefit of using the Adapter pattern?
a) Improved object creation
b) Decoupling objects and automatically updating dependents
c) Bridging between incompatible interfaces
d) Separating the construction process of a complex object from its
representation
34. In the Builder pattern, what is the role of the Director?
a) To define the common methods for handling requests
b) To maintain a list of observers and notify them of state changes
c) To provide a higher-level interface for constructing the product using the
builder
d) To encapsulate a request as an object and support undoable operations
35. Which pattern allows objects to efficiently share a large number of objects by
minimizing memory usage?
a) Singleton
b) Flyweight
c) Command
d) Builder
36. What is the primary role of the Observer pattern?
a) To encapsulate a request as an object and support undoable operations
b) To provide a bridge between two incompatible interfaces
c) To decouple objects and automatically update dependents
d) To separate the construction process of a complex object from its
representation
37. In the Command pattern, what is the role of the Receiver?
a) To define the common methods for handling requests
b) To maintain a list of observers and notify them of state changes
c) To encapsulate a request as an object and support undoable operations
d) To perform the actual action associated with a request
38. Which pattern allows subclasses to decide which class to instantiate?
a) Factory
b) Singleton
c) Builder
d) Adapter
39. What problem does the Facade pattern primarily address?
a) Decoupling senders and receivers
b) Simplifying interactions with a complex subsystem
c) Providing a bridge between two incompatible interfaces
d) Separating the construction process of a complex object from its
representation
40. Which pattern allows objects to efficiently share a large number of fine-grained
objects by separating intrinsic and extrinsic state?
a) Chain of Responsibility
b) Observer
c) Memento
d) Flyweight
42. Which pattern allows objects to capture and restore their internal state without
violating encapsulation?
a) Observer
b) Command
c) Memento
d) Factor
47. In the Command pattern, what is the role of the Receiver?
a) To define the common methods for handling requests
b) To maintain a list of observers and notify them of state changes
c) To encapsulate a request as an object and support undoable operations
d) To perform the actual action associated with a request

1. a) Simplifying interactions with a complex subsystem


2. d) Interoperability
3. c) Capturing and restoring an object's internal state
4. c) It decides whether to process a request or pass it along the chain
5. c) Flyweight
6. b) Decoupling objects and automatically updating dependents
7. b) Singleton
8. c) Providing an interface for creating objects with subclasses deciding which to
instantiate
9. c) Capturing and restoring an object's internal state
10. d) Encapsulating a request as an object and supporting undoable operations
11. a) Creational Patterns
12. a) Separation of concerns
13. c) Facade
14. b) Maintains a list of observers and notifies them of state changes
15. c) Flyweight
16. a) To bridge between incompatible interfaces
17. a) Facade
18. b) Builder
19. d) To allow a request to pass along a chain of handlers until it is handled or
reaches the end of the chain
20. c) Observer
21. d) Product
22. d) Encapsulating a request as an object and supporting undoable operations
23. c) Factory
24. c) Flyweight
25. b) Decoupling objects and automatically updating dependents
26. c) Adapter
27. b) To provide a global point of access to an instance and ensure only one
instance is created per container
28. a) Keeps track of Memento objects and requests them from the Originator to
save or restore the object's state
29. b) Simplifying interactions with a complex subsystem
30. c) Flyweight
31. c) It decides whether to process a request or pass it along the chain
32. c) Memento
33. c) Bridging between incompatible interfaces
34. c) To provide a higher-level interface for constructing the product using the
builder
35. b) Flyweight
36. c) Decoupling objects and automatically updating dependents
37. d) To perform the actual action associated with a request
38. c) Factory
39. b) Simplifying interactions with a complex subsystem
40. c) Flyweight
41. c) It decides whether to process a request or pass it along the chain
42. c) Memento
47. d) To perform the actual action associated with a request

You might also like