Week 2 Flashcards
Name this: “is-a” relationship
Inheritance
Name this: “has-a” relationship
Composition
Inheritance is determined at _______ time, whereas composition is determined at ___ time
compile, run
A subclass if defined in terms of its _________ and can often see the ____________’ internals
superclass. superclass’ internals
In composition a class a_________s with others to gain f____________
associates with others to gain functionality
Name this: Easy to override methods, can’t change at runtime
Inheritnce
Name this: Implementation changes in one level affects its lower level, cascading.
Inheritance
Name this: Respects class interface, interfaces need careful design if they are to be used with many other classes
Composition
Name this: Encapsulation respected, sometimes more classes needed for a solution (more complex)
Composition
For this course: Composition vs Inheritance, which is favoured?
Composition
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?
Object 1 is the delegator, Object 2 is the delegate
Is delegation dynamic? What does that mean? Give an example
Yes it is dynamic, which means it can be changed at runtime. Example: Class “Window” can be a shape other than rectangle.
T/F - A delegator may only delegate one delegate object
False. It may delegate multiple delegate objects
T/F - Many delegators may use a single delegate
True
T/F - A delegate may only expose one method for invocvation
False. It may expose multiple methods for invocation.
Name this ex. of delegation in patterns: Object delegates to a “strategy” for its implementation of a method and can change strategies
Strategy
Name this ex. of delegation in patterns: Object delegates to another which holds a representation of its
current state
State
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
Visitor
T/F - A “delegate” patterns certainly exists.
False, there is debate over whether it exists
T/F - Delegation is a technique or principal
True
When is the singleton pattern useful? What are some examples?
When you need to guarantee that only 1 instance is created and used throughout the application. Example would be a database or network connection.
The basic approach for the singleton pattern is
_______ constructor
_____ variable
_____ method
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)
Name this: Ensures a class has one instance and provide a global point of access to it.
Singleton
This design pattern separates the construction object from the details of its representation or component objects
Builder