Programming TEST QUESTIONS &
ANSWERS ALREADY GRADED A+ 2025
Terms in this set (174)
Intent of Command To encapsulate a function call as an object.
Pattern
Consequence of Decouples objects that invoke a given operation with ones that
Command Pattern know how to perform it.
Intent of the Interpreter Define a representation for a languages grammar along with
Pattern an interpreter that uses the representation to interpret
sentences of that language.
Consequence of It's easy to change and extend the grammar (generally just add
Interpreter Pattern a new class).
Intent of the Iterator It provides a way to access elements of an aggregate
pattern collection without exposing the underlying representation.
Consequence of the They support variations in the interpretation of a collection or
Iterator pattern aggregate. With complex collections the desired type of
traversal may change and using this pattern makes it easier to
change the traversal algorithm.
What is a robust iterator? An iterator that ensures that insertions and removals won't
interfere with traversal, and does so without copying the
collection.
Without violating encapsulation (private variables), it
What is the intent of the
allows one to capture and externalize an object's internal
Memento Pattern?
state so that the object can later be restored to that state.
,Consequence of the It provides encapsulation boundaries. And prevents the
Memento Pattern exposure of contents while enabling an object to store its
state.
What is the intent of the To allow an object to alter its behavior when its
State Pattern? internal state changes. The object will appear to
change its class.
Consequence of the State It localizes the state-specific behavior and partitions behavior for
Pattern different states.
What is the intent of the It defines a family of algorithms, encapsulating each one
Strategy Pattern? and then makes them interchangeable. The algorithms
are also decoupled from clients.
Consequence of the They create families of related algorithms and can leverage
Strategy Pattern inheritance to simplify implementation of commonly-used
functionality.
What is the intent of the To define a new operation without changing the classes of
Visitor Pattern? the elements on which it operated to. It represents an
operation to be performed on elements of an object
structure as a class.
Consequence of the The adding of new operations becomes easy as it removes the
Visitor Pattern task of modifying existing classes.
What is the intent of the To compose objects into tree structures and represent part-
Composite Pattern? whole hierarchies. It lets clients treat individual objects and
compositions of objects uniformly.
Consequence of the They define a class hierarchy of primitive and composite
Composite Pattern objects.
Shearing Layer The state in which between layers where they change from
one speed to another. One layer may be changing slower
than another.
, Program to Interface
Two main design principles
Favor Composition over Inheritance
Program to Interface We don't know what something does. In fact it is better
that we don't know as each time an operation happens
there is a different implementation of the interface.
Example: Accept => Turtle, Accept => Visitor
Favor Composition over Composition gives us flexibility like the strategy pattern.
Inheritance Instead of creating subclasses to store priority at compile
time, use a priority class to change it during runtime.
Coupling One class knowing about the other.
Ex. Turn Expression knowing about the Memento.
(coupled). Also Expressions and Visitors.
Cohesion This is good. We want lots of it. When looking at a class or
function, what is the task that we are trying to accomplish?
Putting "PrintStudents" in a priority queue will make it less
cohesive.
The interpreter pattern is False. It is not going to be as efficient as assembly code.
efficient.
Difference between State Structure is the same. State expects that the object should
and Strategy pattern change its state frequently while the Strategy typically does
not.
Is adding a new Visitor Yes but if you add a new type of visit or the grammar
easy? changes, you must go to each visitor class and change the
grammar/new type to visit.
What design pattern Iterator. We don't know the structure because the iterator
reduces coupling handles that.
between classes?