Week 2 Flashcards

1
Q

Name this: “is-a” relationship

A

Inheritance

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

Name this: “has-a” relationship

A

Composition

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

Inheritance is determined at _______ time, whereas composition is determined at ___ time

A

compile, run

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

A subclass if defined in terms of its _________ and can often see the ____________’ internals

A

superclass. superclass’ internals

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

In composition a class a_________s with others to gain f____________

A

associates with others to gain functionality

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

Name this: Easy to override methods, can’t change at runtime

A

Inheritnce

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

Name this: Implementation changes in one level affects its lower level, cascading.

A

Inheritance

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

Name this: Respects class interface, interfaces need careful design if they are to be used with many other classes

A

Composition

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

Name this: Encapsulation respected, sometimes more classes needed for a solution (more complex)

A

Composition

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

For this course: Composition vs Inheritance, which is favoured?

A

Composition

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

Object 1 has a reference to object 2 and uses that to access methods in object 2. Object 1 is giving the responsibility of operations to object 2.

Who is the delegator, who is the delegate?

A

Object 1 is the delegator, Object 2 is the delegate

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

Is delegation dynamic? What does that mean? Give an example

A

Yes it is dynamic, which means it can be changed at runtime. Example: Class “Window” can be a shape other than rectangle.

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

T/F - A delegator may only delegate one delegate object

A

False. It may delegate multiple delegate objects

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

T/F - Many delegators may use a single delegate

A

True

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

T/F - A delegate may only expose one method for invocvation

A

False. It may expose multiple methods for invocation.

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

Name this ex. of delegation in patterns: Object delegates to a “strategy” for its implementation of a method and can change strategies

A

Strategy

17
Q

Name this ex. of delegation in patterns: Object delegates to another which holds a representation of its
current state

A

State

18
Q

Name this ex. of delegation in patterns: Object delegates an operation to a “visitor” and that operation is
repeated for each of the object’s structure

A

Visitor

19
Q

T/F - A “delegate” patterns certainly exists.

A

False, there is debate over whether it exists

20
Q

T/F - Delegation is a technique or principal

A

True

21
Q

When is the singleton pattern useful? What are some examples?

A

When you need to guarantee that only 1 instance is created and used throughout the application. Example would be a database or network connection.

22
Q

The basic approach for the singleton pattern is

_______ constructor
_____ variable
_____ method

A

Private constructor (Prevent it from being called multiple times),
static variable (Store reference to a single instance),
static method (Returns reference to a single instance)

23
Q

Name this: Ensures a class has one instance and provide a global point of access to it.

A

Singleton

24
Q

This design pattern separates the construction object from the details of its representation or component objects

A

Builder

25
Q

This design pattern often has complex objects such as composites or objects composed of multiple objects

A

Builder

26
Q

What is more flexible, builder pattern or factory pattern?

A

Builder

27
Q

Explain the 4 steps in the Builders basic approach

A
  1. Uses director class responsible for order and use of build instructions
  2. Concrete builder creates the complex object
  3. Director adjusts build instructions to obtain different types of objects
  4. Director may change the concrete builder to build the same type of object differently
28
Q

T/F - One of the benefits of inheritance is its contributions to encapsulation

A

False. Inheritance breaks encapsulation, as it exposes the subclass to the details of its parents implementation

29
Q

T/F - Delegation makes composition as powerful for reuse as inheritance

A

True

30
Q

For the strategy pattern, we let the algorithm vary independently from clients that use it. This is called ______ a____________

A

Policy applicability

31
Q

When do we apply policy applicability?

A

When many related classes differ only in there behaviour. It allows us to apply different variants of a given algorithm