Software Engineering - Module6 Exercises (Principles and Patterns)
Software Engineering - Module6 Exercises (Principles and Patterns)
M8 Software Engineering
Activities Availability date Due date
Module 6 29/04/2024 17/05/2024
Module 6 Assignments
Activity 1:
Which of the following are benefits from low-coupling of classes, or making classes independent,
in our software design:
A: Changes are localised
B: Changes in related classes force local changes
B: Easier to understand code
C: Easier to reuse code
Activity 2:
Which of the following are benefits from the high-cohesion principle of classes in our software
design:
A: A Class is solely responsible for many things in very different functional areas
B: The class is easier to understand
C: Classes are easier to maintain
D: Supports reuse because of fine grained responsibility
Activity 3:
According to the information expert design principle, we should assign a responsibility to the
object class that has the information necessary to fulfill this responsibility.
Who is the information expert among the objects of the diagram below, to determine the grand
total (Line items and the sum of their subtotals)
A: Sales LineItem
B: Product Specification
C: Sale
D: None of the above
Activity 4:
According to the creator design principle, the class B who has responsibility of creating instance of
class A, usually needs to keep reference and will frequently use the created object A.
Who is responsible for creating SalesLineItem objects in our system that has the following
sequence diagram?
A: SalesLineItem
B: Customer
C: Register
D: Sale
Activity 5:
a) In a system without a controller, the classes in the View tier directly interact with classes
in the Model
b) A GRASP Controller is placed in the Controller tier and provides services that encapsulate
application logic
c) This usually manifests as lots of little interactions such as constructor and method calls
d) This often has the effect of replacing several method calls with a single call to the service
e) The result is that the View classes become more complex, more tightly coupled with the
model, and less focus on UI tasks like receiving input and rendering output
f) Assign responsibility to receive and coordinate a system operation to a class outside of
the UI tier
g) The UI is harder to replace - it requires that complex application logic be rewritten in each
new UI (e.g. web, mobile, desktop, etc.)
h) In simple systems, it may be a single object that coordinates all system operations. In
more complex systems, it is often multiple objects from different classes, each of which
handles a small set of closely related operations
Step Tasks
GRASP
b),…
Controller
Without
a),…
Controller
Activity 6:
Which of the following statements are aligned with good design principles?
A: Increase cohesion where possible
B: Increase coupling where possible
C: Provide well-defined, conceptual boundaries that focus on the outside view of an object and so
serves to separate an object’s essential behavior from its implementation
D: To extend the behavior of a system, we add new code. We do not modify old code
Activity 7:
Which of the following statements are true for the next class diagram of the strategy design
pattern:
A: The Context class has the responsibility of creating a reference to a specific strategy
B: The Strategy class inherits the specific algorithm from ConcreteStrategy (A and B)
C: The Strategy class works as an interface, that is shared by the different algorithms
D: The ConcreteStrategy (A and B) class is the one actually implementing the algorithm
Activity 8:
Which of the following are true about the factory method design pattern:
A: It’s a structural behavior pattern
B: It decouples client code from the concrete classes, reducing dependencies and enhancing code
stability
C: It allows for the creation of objects without specifying their exact class, making the code more
flexible and maintainable
D: New product classes can be added without modifying existing code, promoting an open-closed
principle (open for extensions, closed for modifications)
Activity 9:
What are the reasons for using the decorator design pattern?
A: The Decorator class aggregates other types of components which will allow us to stack
components on top of each other
B: The pattern allows objects to dynamically add behaviors to others.
C: To reduce the number of classes needed to offer a combination of behaviors