Software Construction: Object-Oriented Design Flashcards

1
Q

A call-stack is formed when

A

one method calls another.

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

Exception mechanisms in a programming language let us

A

write code to recover from errors, and resume normal execution of the code.

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

Throwing the exception object causes

A

an alternate return path to be taken: once an exception is thrown, none of the subsequent code in that method is executed. Instead, the exception object can be thought of as falling back down the return path to the calling method

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

Normal execution through the normal return path does not

A

resume until the exception is caught. If the exception is not caught it keeps falling down the alternate exceptional path until the program effectively crashes.

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

A method should only catch an exception if it can actually

A

do the work to recover from (handle) that exception.

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

unchecked exceptions and checked exceptions

A

unchecked doesnt check by java, checked - checked

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

To Extract a class hierarchy

A

we look at all the “extends” and “implements” relationships between classes and interfaces in our system.

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

To Extract associations

A

we look at the fields within the classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
If a class contains a field of another type, then...
We would draw the association on the diagram, and indicate...
A
...we say that the class is associated with that other type.
...what the arity of the association i
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An Aggregation relationship can be thought of as

A

a whole-part relationship. If one object is part of another object, then we use a diamond at the start of the arrow (next to the containing object), and a normal arrow at the end.

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

A sequence diagram depicts

A

the calls between objects while the system is running. It’s essentially a vertical timeline of calls, that flows from top to bottom.

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

A sequence diagram starts

A

with a particular method call – so effectively, we are drawing the sequence of calls triggered by one method.

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

At the top of the diagram,

A

all the objects that are “alive” through the execution of the method are depicted. They then have lifelines (timelines) extending down from them.

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

To show a method’s execution on the timeline, we draw

A

a box that overlays the timeline. The box extends for as long as that method runs.

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

Calls to a method are depicted as

A

arrows with the name of the method sitting as the label. Parameters are listed in parentheses. The destination object for a call is the object in which that method is implemented. The call arrow extends from the calling object’s method to the called method.

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

Loops are shown in sequence diagram by

A

placing a box around all the looped behaviour, and putting the condition of the loop in the corner.

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

Conditional behaviour in sequence diagram is shown as

A

a box around all the conditional behaviour, with the condition indicated in the corner.

18
Q

To Implement Fields we look at

A

associations between classes.

19
Q

The type of the field is determined by

A

the destination type of the association arrow.

20
Q

There are three kinds of Bi-Directional Relationships

A

one-one relationships, one-many relationships, and many-many relationships.

21
Q

When Implementing Sequence Diagrams begin by looking at

A

the method coming in from the side – this tells us the name of the method being implemented.

22
Q

SOLID

A

Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation and Dependency Inversion. Of those we will look at Single Responsibility and Liskov Substitution

23
Q

The Single Responsibility Principle indicates that

A

each class should be centered around one cohesive concept

24
Q

If, over time, a class seems like it has more than one responsibility, it can be

A

split into two separate classes

25
Q

A symptom of having two responsibilities is

A

having multiple clusters of methods, with each cluster referring to their own data within the class. Each cluster may represent its own responsibility, and may be best separated into its own class.

26
Q

Coupling between two classes indicates that

A

two classes collaborate in some way.

27
Q

Inter-class coupling can be through

A

method calls, dependencies, or by holding functionality in common that accomplishes a goal without explicitly declaring as such.

28
Q

Low coupling

A

a change in one place requires no change in a collaborating class

29
Q

Medium coupling

A

a change in one class does require a remote change, but the compiler warns the developer that the change is needed. An example of this is when a checked exception is declared to be thrown, the compiler will alert the developer that it must be caught at the calling location. Method signature changes are also checked by the compiler, as are Type changes.

30
Q

High coupling

A

a change in one class does require a remote change, but the collaboration will only be detected at runtime – meaning you have to run the code to see that the change has affected other classes.

31
Q

One way to refactor semantic coupling is to

A

introduce a new type of object to reduce duplication.

32
Q

The Liskov Substitution Principle states that

A

for a subclass to be substitutable for its superclass, the subclass cannot break the expectations that a user of the superclass would have. Thus, it cannot reduce the service it provides, and cannot produce effects not produced in the superclass.

It formally states that

the preconditions of a subclass’s behaviour (methods) cannot be strengthened, meaning (among other things) that a sub-method cannot accept a narrower range of inputs than the original method.

The post conditions of a sub-method cannot be weakened, meaning that the sub-method cannot have a broader range of effect than the original method.

33
Q

Тип тестов для LSP

A
- substitution test
Student s = new StudentRegSys();
Bird b = new Eagle();
- concatenation test
StudentRegSys Student
Eagle Bird
-IS-A test
StudentRegSys IS-A Student
Eagle IS-A Bird
34
Q

The Composite Pattern provides

A

a design for a hierarchy, in which nodes with children differ in their behaviour from nodes with no children. An example might be the display of a hierarchy, like a file system, where folders contain files. Folders would be displayed differently from files, and would have contents (the files).

35
Q

The composite pattern consists of

A

three classes: the Composite (the node that can have children), the Leaf (no children), and the Component, which is a superclass extended by both the Composite and Leaf

36
Q

The Composite has a collection

A

of Components, so that the Composite class can loop through those Components without keeping track of whether the Component is actually a Composite or a Leaf.

37
Q

The Composite also has an method

A

addComponent method so that Components can be added to its contents.

38
Q

Without the Component super class abstraction,

A

the Composite would have to maintain different lists for each kind of element in its contents, and would need to provide individual methods for adding contents, and displaying contents for each kind of content.

39
Q

The Observer Pattern is a design that lets

A

one or more objects watch the state of one or more other objects.

40
Q

The Observer Pattern design centers around two phases

A

Registration: The Observer registers with the Subject, by calling a registration method on the subject (named something like register, or addObservers). In that method, the Subject adds the Observer to its list of Observers.

Notification: Whenever the Subject’s state changes, it notifies the observers by calling its own notify (or similarly named) method. The notify method then iterates through the list of observers, calling update (or a similarly named method) on each one. The Subject may send an argument with this method to indicate the change (the push model), or may send a reference to itself so that the Observer can call back to find out what changed for itself (the pull model).

41
Q

The Iterator Pattern allows us to

A

separate out all the logic for iterating over a collection.