Lecture 10 - GRASP Flashcards

1
Q

What is the focus of object design?

A

Identify classes and objects, decide what methods belong were, and how these objects should interact

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are responsibilities regarding objects?

A

Obligation of an object in terms of behaviour

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two types of responsibilities regarding objects?

A
  • Doing
  • Knowing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the Doing responsibility do regarding objects? (3)

A
  • Doing something (i.e. creating object, doing calculation)
  • Initiating action in other objects
  • Controlling + coordinating activities in other objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does Knowing responsibility do regarding objects? (3)

A
  • Knowing about private encapsulated data
  • Knowing about related objects
  • Knowing about things it can derive or calculate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When are responsibilities assigned to classes?

A

During object design

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

“A sale is responsible for creating a SalesLineItems” is an example of…

A

the Doing responsibility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“A sale is responsible for knowing its total” is an example of…

A

the Knowing responsibility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

TF: Responsibilities related to “Knowing” are often inferable from the Domain Model

A

True. Because of attributes and associations illustrated in it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The translation of responsibilities into classes and methods is influenced by what?

A

Granularity of responsibility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

TF: Responsibility is the same thing as a method

A

False. Methods are implemented to fulfill responsibilities, but they are not the same thing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Within UML artifacts, what is a common context in which responsibilities are considered?

A

During the creating of Interaction Diagrams

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do Patterns guide?

A

Guide choices in where to assign responsibilities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a named description of a problem and a solution that can be applied to new contexts?

A

Patterns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

TF: A pattern provides advice in how to apply a solution to a problem in varying circumstances

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the basic idea of Information Expert?

A

To assign a responsibility to the object (class) that has the most information necessary to fulfill it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Fulfillment of a responsibility often requires information spread across different classes, what can the other classes be known as?

A

Partial experts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The class responsible for creating instances of another class is called a…

A

Creator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What conditions does a class ‘A’ need to satisfy to be considered a Creator for class ‘B’? (4)

A
  • A aggregates B objects
  • A contains B objects
  • A records instances of B objects
  • A has the initializing data that will be passed when B is created
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the problem with Solution by Expert?

A

Can sacrifice high cohesion and low coupling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a design pattern that doesn’t sacrifice high cohesion and low coupling?

A

Pure fabrication

22
Q

What is pure fabrication pattern?

A

A pattern in which a separate class that doesn’t represent a domain concept is created to handle a responsibility

23
Q

How can you enforce low coupling?

A

By assigning a responsibility to ensure coupling stays low

24
Q

What are the places where coupling occurs? (4)

A
  • Attributes: X has attribute that refers to Y
  • Methods: parameters/local variables of type Y found in method of X
  • Subclasses: X subclass of Y
  • Types: X implements interface Y
25
Q

What is Protected variation pattern?

A

Pattern aimed to reduce variation/instability in one element from having undesirable effects on other elements

26
Q

What is a way to incorporate Protected variation?

A

By encapsulating elements that could vary (using interfaces or abstract classes)

27
Q

TF: A benefit of Protected variation is it makes the system easier to maintain and understand

A

True

28
Q

What is Open-closed pattern?

A

Pattern where classes, modules, functions should be open for extension but closed for modification

29
Q

How do you apply the Open-closed pattern?

A

By identifying points of predicted changes/extension within components and create stable interfaces or extension points

30
Q

Extensibility of individual software components (easy extension without modifying existing code) is the goal of what pattern?

A

Open-closed pattern

31
Q

Managing dependencies between components to protect against changes in other components (using abstraction/interfaces to minimize direct dependencies) is the goal of what pattern?

A

Protected variation pattern

32
Q

What is the similarity between Open-closed pattern and Protected variation pattern?

A

Use of interfaces/abstraction to protect components from changes or variation

33
Q

What are the problems with low cohesion? (4)

A
  • Hard to understand
  • Hard to reuse
  • Hard to maintain
  • Easily affected by change
34
Q

How to enforce high cohesion?

A

Assign a responsibility so cohesion remains high

35
Q

A class responsible for interfacing with a data based on remote-procedure calls is an example of what type of cohesion?

A

Very low cohesion

36
Q

A class responsible for interfacing with a relational database is an example of what type of cohesion?

A

Low cohesion

37
Q

Airline class that knows about personnel and finance is an example of what type of cohesion?

A

Moderate cohesion

38
Q

A class responsible for one section of interfacing with a database (i.e Sale object in a POS)?

A

Class/High cohesion

39
Q

TF: A class with high cohesion has a relatively low number of methods that are highly related

A

True

40
Q

TF: A class with high cohesion does a lot of work

A

False. It doesn’t do much work and mostly collaborates and delegates

41
Q

What is the Controller Pattern?

A

Pattern in which responsibility for receiving or handling a system event message is assigned to a class

42
Q

The class selected as the Controller must represent what? (3)

A

One of the following:
- Represents overall system
- Represents a use case scenario
- A Controller is a non-user interface object that defines methods for the system operation

43
Q

What is indirection?

A

Measure of how abstracted and managed the relationships and dependencies between software components are

44
Q

How can we manage relationships and dependencies between components effectively and maintainable?

A

Assign responsibilities for managing relationships and dependencies using abstraction layers (a.k.a indirection)

45
Q

When complex systems need to maintain flexibility and compatibility across various implementation, you should use…

A

an interface

46
Q

In scenarios where specific behaviours or attributes must be realized with precision and consistency, you should use…

A

a class

47
Q

Which design principle can help address concerns about the impact of changes in a system and promote well-organized code?
a. Creator
b. Information Expert
c. High Cohesion
d. All of the mentioned

A

c. High Cohesion

48
Q

In a system adhering to the Creator pattern in GRASP, how are responsibilities assigned for creating Payment and processing it between Sale and Register?
a. Sale creates Payment, and Register serves as a Controller to facilitate payment processing.
b. Sale creates Payment, and Register is not directly involved in payment processing.
c. Register creates Payment, and Sale processes payments.
d. None of the above.

A

a. Sale creates Payment, and Register serves as a Controller to facilitate payment processing.

49
Q

What is the primary advantage of using the Information Expert pattern for responsibility assignment in object-oriented design?
a. It promotes high cohesion and low coupling between objects.
b. It simplifies the structure of the system.
c. It allows for more flexible and dynamic object interactions.
d. It reduces the number of objects in the system, leading to improved performance

A

a. It promotes high cohesion and low coupling between objects.

50
Q

With regard to the creator pattern, we should assign class B the responsibility of creating an instance of class A if which of the following conditions are true?
a. A records B
b. B knows about A
c. B closely uses A
d. All of the above

A

b. B knows about A

51
Q

All are correct about pure fabrication pattern except:
a. Achieve low coupling
b. Achieve high cohesion
c. Represent a concept in theproblem domain
d. Represent a concept in thesolution domain

A

c. Represent a concept in theproblem domain