[go: up one dir, main page]

0% found this document useful (0 votes)
45 views11 pages

GRASP Patterns

Uploaded by

kinanov115
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views11 pages

GRASP Patterns

Uploaded by

kinanov115
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

GRASP patterns

1- In a content management system for a blogging platform, there is a class


named BlogPostFactory responsible for creating instances of BlogPost objects.
This factory class encapsulates the logic for initializing and configuring blog posts
with default settings. When considering GRASP principles, which option best
describes the role of the BlogPostFactory class?
A Creator
B. Controller
C. Low Coupling
D. Pure Fabrication
2- In a video game development environment, there is a class called
WeaponFactory responsible for generating different types of weapons with
specific attributes such as damage, range, and ammunition. This class
centralizes the logic to ensure consistency across weapons. When applying
GRASP principles, which option correctly identifies the role of the WeaponFactory
class?
A Creator
B. Controller
C. Information Expert
D. High Cohesion
3- In an online reservation system for a restaurant, there is a class named
ReservationHandler responsible for managing the creation of reservation
instances, handling table assignments, and sending confirmation emails to
customers. This class encapsulates the reservation process and ensures proper
coordination. According to GRASP principles, which option correctly characterizes
the role of the ReservationHandler class?
A. Controller
B. Creator
C. Low Coupling
D. Indirection
4. In a music streaming application, there is a class called PlaylistManager
responsible for organizing and managing playlists. This class handles the
addition, removal, and reordering of songs within a playlist, as well as generating
recommendations based on user preferences. According to GRASP principles,
which option accurately describes the role of the PlaylistManager class?
A. Controller
B. Information Expert
C. Low Coupling
D. Creator
5- Which GRASP pattern promotes low coupling by assigning the responsibility for
handling a particular task to a class that represents the most general abstraction
related to that task?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) High Cohesion
6- In the context of GRASP patterns, which design principle aims to reduce the
dependencies between classes, promoting low coupling by ensuring that one
class is responsible for coordinating the activities of others?
A) Information Expert
B) Controller
C) Creator
D) Polymorphism
E) High Cohesion
7- In a software system for a library management application, there is a need for
a class that handles the communication between the user interface and the
database, performing complex queries and data processing without belonging to
the domain layer. The goal is to avoid introducing unnecessary dependencies
between the UI and database classes.
A) Information Expert
B) pure fabrication
C) Creator
D) Polymorphism
E) High Cohesion
8- In a complex software system, there is a requirement for a class that can
dynamically adapt its behavior based on the type of object it interacts with,
without knowing the specific class of that object. Which GRASP pattern is most
appropriate to handle this scenario?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) Pure Fabrication
9. In a graphical user interface (GUI) application, there is a need for a class to
handle user input and manage the flow of control between different components.
Which GRASP pattern is most suitable for assigning this responsibility?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) High Cohesion
10- In a software system, there is a need for a class to encapsulate the
knowledge of a specific domain concept and provide services related to that
concept. Which GRASP pattern is most appropriate for assigning this
responsibility?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) High Cohesion
11- In a system where different parts need to collaborate without direct
dependencies, there is a requirement for a class that acts as an intermediary to
facilitate communication and coordination. Which GRASP pattern is best suited
for assigning this responsibility?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) Pure Fabrication
12- In a software system, there is a need for a class to create and initialize
instances of various collaborating classes. However, the exact classes to be
instantiated may vary based on specific conditions. Which GRASP pattern is most
appropriate for assigning this responsibility?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) High Cohesion
13- In a system where there is a need for a class to encapsulate complex
business rules and make decisions based on various factors within the system,
which GRASP pattern is most suitable for assigning this responsibility?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) High Cohesion
13- In a system where there is a need to minimize dependencies between
classes and achieve low coupling, which GRASP pattern is most appropriate for
assigning responsibilities to ensure that one class is responsible for coordinating
the activities of others?
A) Information Expert
B) Creator
C) Controller
D) Polymorphism
E) Pure Fabrication
14- In the context of software design principles, why is low coupling desirable in
a system, and how does it contribute to better software architecture?
A) Low coupling reduces code duplication.
B) Low coupling enhances code readability.
C) Low coupling minimizes the impact of changes in one module on other
modules.
D) Low coupling increases the efficiency of code execution.
E) Low coupling ensures a higher degree of abstraction.
15- What is a characteristic of low cohesion in a software design?
A) Modules performing a single, specific task.
B) ByModules having strong interconnections and dependencies.
C) Modules sharing a common set of attributes and methods.
D) Modules being independent and loosely connected.
E) Modules having a high degree of internal consistency.
16- Which of the following best describes a characteristic of high cohesion in
software design?
A) Modules performing a wide range of unrelated tasks.
B) Modules having strong interconnections and dependencies. C) Modules
sharing a common set of attributes and methods.
D) Modules being independent and loosely connected.
E) Modules with a high degree of internal consistency, focusing on a specific
functionality.
17- In the context of the "Information Expert" GRASP pattern, which of the
following statements is true?
A) Information Expert suggests that classes should have minimal information
about each other to achieve low coupling.
B) Information Expert recommends creating classes with a wide range of
responsibilities for flexibility.
C) Information Expert advises assigning a responsibility to the class that
possesses the required "information to fulfill that responsibility.
D) Information Expert encourages the use of abstract classes over concrete
classes.
E) Information Expert focuses on creating classes that encapsulate complex
business rules within a single module.
18- In the context of the "Controller" GRASP pattern, what is the primary
responsibility of a controller class?
A) Managing the flow of control between different components.
B) Creating and initializing instances of collaborating classes.
C) Encapsulating complex business rules within a single class.
D) Serving as an intermediary to facilitate communication and coordination.
E) Promoting low coupling by creating classes solely for the purpose of
coordination.
19. In the context of the "Pure Fabrication" GRASP pattern, what is the primary
purpose of introducing a class that is a pure fabrication?
A) To create classes solely for the purpose of achieving low coupling.
B) To encapsulate complex business rules within a single class.
C) To represent real-world entities in the system.
D) To promote high cohesion by grouping related classes together.
E) To facilitate communication and coordination between different components.
20- In the context of the "Creator" GRASP pattern, which of the following is a
guideline for assigning the responsibility of creating an instance of a class?
A) The class that creates another class should be the one with the fewest
dependencies.
B) The class that creates another class should be the one that uses it the most.
C) The class that creates another class should be the one that is used by it the
most.
D) The class that creates another class should be the one with the least
knowledge about the other class.
E) The class that creates another class should be the one with the most
knowledge about the other class.
1. In a logistics management system, a class named ShippingManager is
responsible for orchestrating shipping activities, including calculating
costs, scheduling deliveries, and notifying customers. Which GRASP
pattern is most applicable to this class?
A) Controller
B) Polymorphism
C) Low Coupling
D) Information Expert
2. In an e-commerce platform, a class named OrderFactory is responsible for
creating new order objects with pre-filled details like customer information
and cart contents. This ensures consistent initialization of orders. Which
GRASP principle does this demonstrate?
A) Controller
B) Creator
C) Polymorphism
D) Pure Fabrication
3. A media streaming app uses a RecommendationEngine class to provide
content suggestions based on user history and preferences. Which GRASP
pattern does this represent?
A) Information Expert
B) Low Coupling
C) High Cohesion
D) Controller
4. In a finance application, a class TransactionProcessor ensures that
business rules for transactions are strictly followed, and calculates taxes
and fees for each transaction. Which GRASP pattern does this
responsibility align with?
A) Creator
B) Information Expert
C) Controller
D) Polymorphism
5. In a healthcare management system, the AppointmentScheduler class acts
as an intermediary between the user interface and the database for
managing appointments. Which GRASP principle is applied here?
A) Pure Fabrication
B) Low Coupling
C) High Cohesion
D) Polymorphism
6. A class PaymentHandler in an e-commerce system encapsulates complex
logic for managing various payment methods (credit card, PayPal, etc.).
Which GRASP pattern is demonstrated by assigning this responsibility?
A) Controller
B) Polymorphism
C) High Cohesion
D) Information Expert
7. Which GRASP pattern ensures a low dependency design by assigning tasks
to the class that has access to the required information?
A) Creator
B) Information Expert
C) Polymorphism
D) Controller
8. In a gaming application, a GameAction interface is used to support
multiple types of actions (move, attack, defend) without depending on
specific classes. Which GRASP principle is this?
A) High Cohesion
B) Polymorphism
C) Pure Fabrication
D) Creator
9. In a messaging app, a MessageFormatter class is introduced solely to
handle formatting messages into various styles (plain text, HTML). This
class does not exist in the domain model. Which GRASP pattern is
represented here?
A) Pure Fabrication
B) High Cohesion
C) Information Expert
D) Controller
10.What is the primary benefit of applying the Low Coupling GRASP
principle?
A) Enhanced system performance
B) Easier debugging and maintenance
C) Improved scalability
D) Reduced memory consumption
11.A highly cohesive class typically performs which type of tasks?
A) A wide range of unrelated tasks
B) A single, specific task
C) Tasks requiring extensive inter-class communication
D) Coordination tasks for other classes
12.In the Creator GRASP pattern, which class is most suitable for creating an
object?
A) The class that aggregates the created object
B) The class that is most abstract
C) The class with the least dependencies
D) The class with no relation to the created object
13.A Pure Fabrication class is introduced for which purpose?
A) Simplifying domain modeling
B) Reducing domain-level complexity
C) Supporting low-level functionalities
D) Representing real-world entities
14.Which GRASP pattern is most suitable for dynamically selecting the
behavior of a class at runtime?
A) Polymorphism
B) Creator
C) Controller
D) Pure Fabrication
15.In the context of High Cohesion, what is a drawback of low cohesion?
A) High dependency
B) Complex debugging
C) Poor modularity
D) All of the above
16.What does the Controller GRASP pattern primarily focus on?
A) Inter-class communication
B) Application-specific logic
C) Delegating actions to the UI layer
D) Managing system events
17.Which GRASP pattern would you apply to reduce the impact of changes to
the domain logic in a highly coupled system?
A) Polymorphism
B) Low Coupling
C) High Cohesion
D) Information Expert
18.A Polymorphism-oriented design helps to:
A) Create objects flexibly
B) Centralize responsibilities
C) Manage variations based on type
D) Reduce coupling
19.Which GRASP principle aligns with designing a class that owns the data
and performs operations on that data?
A) Creator
B) Pure Fabrication
C) Information Expert
D) Controller
20.Indirection as a GRASP principle is used to:
A) Increase coupling between components
B) Simplify relationships between modules
C) Add complexity to reduce redundancy
D) Facilitate high-level coordination
21.In a payroll application, the PayCalculator class is assigned responsibility
for computing salary deductions based on predefined rules. Which GRASP
pattern is most suitable?
A) Creator
B) Information Expert
C) Controller
D) Pure Fabrication
Definition
Information Expert
 What it does: Assigns responsibility to the class that has the necessary
information to perform the task.
 Example: If a class has details about an object (e.g., "Employee" knows
their own salary), it should calculate the salary rather than involving
unrelated classes.
 Why it matters: Ensures tasks are handled by the most knowledgeable
class, making the system logical and reducing dependencies.

2. Creator
 What it does: Assigns the responsibility of creating an object to a class
that either:
o Uses the object,

o Has enough information to initialize it, or

o Closely relates to the object.

 Example: An "Order" class might create an "OrderLine" object because it


uses it to represent items in an order.
 Why it matters: Makes sure objects are created logically, reducing
unnecessary coupling between classes.

3. Controller
 What it does: Assigns responsibility for handling user/system interactions
to a "Controller" class.
 Example: In a restaurant system, the "ReservationHandler" class acts as
the controller, managing user inputs like table bookings.
 Why it matters: Keeps the UI and backend logic separate, simplifying
maintenance.

4. Polymorphism
 What it does: Allows a class to dynamically adapt its behavior based on
the type of object it interacts with.
 Example: A "PaymentProcessor" could process payments differently for
"CreditCard" and "PayPal" objects, without knowing their exact types.
 Why it matters: Makes the system flexible and extendable without
modifying existing code.
5. Indirection
 What it does: Assigns responsibility to an intermediary to reduce
coupling between classes.
 Example: A "DatabaseAdapter" can handle communication between a
system and the database, allowing you to change the database without
affecting the system.
 Why it matters: Adds a layer of abstraction, making systems more
adaptable to change.

6. High Cohesion
 What it does: Ensures that a class is focused and only handles closely
related responsibilities.
 Example: A "Customer" class handles customer-related tasks like
updating personal information but doesn’t deal with unrelated tasks like
payment processing.
 Why it matters: Makes classes easier to understand and maintain.

7. Low Coupling
 What it does: Minimizes dependencies between classes so changes in
one class don’t heavily affect others.
 Example: If "Order" interacts with "Customer," it should do so through a
clear, well-defined interface rather than knowing the inner workings of
"Customer."
 Why it matters: Makes the system flexible and easier to modify.

8. Pure Fabrication
 What it does: Introduces an artificial class solely to handle a
responsibility that doesn’t naturally belong to any existing class.
 Example: Creating a "LoggingManager" class to handle all logging
operations in a system.
 Why it matters: Improves design by focusing on responsibilities that
might otherwise be scattered or misfit in existing classes.

You might also like