WorksheetsGeneral Design patterns & principles
Total questions: 15
Worksheet time: 23mins
"Identify the aspects of your application that vary and separate them from what stays the same." results in:
More flexibility in your systems.
Less classes in your systems.
Less interfaces in your systems.
Tighter coupling of your system.
"Program to an interface, not an implementation." means:
Do not program to an abstract superclass.
Program to a supertype.
If possible, put everything in one class.
Go for a concrete implementation whenever possible.
Show answersExplanationPreviousNext
"Favor composition over inheritance." says:
Use the Composite Pattern instead of inheritance.
IS-A is always better than HAS-A
HAS-A can be better than IS-A
Do not use inheritance.
Show answersExplanationPreviousNext
"Strive for loosely coupled designs between objects that interact." does NOT mean:
When two objects are loosely coupled, they can interact, but have very little knowledge of each other.
Interdependency between objects is minimized.
Loosely coupled designs allow to build flexible OO systems.
Interdependency between objects is maximized.
The Dependency Inversion Principle says:
Depend upon abstraction. Do not depend upon concrete classes.
Don't call us, we call you.
Program to an interface, not an implementation.
Favor composition over inheritance.
The Single Responsibility Principle says
Favor composition over inheritance.
A class should have only one reason to change.
Depend upon abstractions.Do not depend upon concrete classes.
Classes should be open for extensions, but closed for modification.
Which text below describes the Template Method pattern best?
Subclasses decide how to implement steps in an algorithm.
Allows (a group of) objects to be notified when some state changes.
Encapsulates interchangeable behaviours and uses delegation to decide which one to use.
Template method pattern changes the interface of one or more classes.
What is NOT a correct statement for the Hollywood Principle?
Call us, we don't call you.
A low-level component never calls a high-level component directly.
It is a way to prevent dependency rot.
High-level components control when and how low-level components participate in the computation.
Which text below describes the Strategy Pattern best?
Encapsulates interchangeable behaviours and uses delegation to decide which one to use.
Provides a way to traverse a collection of objects without exposing the collection's implementation.
Client treats collections of objects and individual objects uniformly.
Simplifies the interface of a group of classes.
What is a proper design principle?
Program to an interface, not an implementation.
Use abstract classes to implement what varies.
The number of classes should be identical with the number of interfaces.
Put what varies and what stays the same together. Do ti so that starting with an abstract class, all other classes inherit in a clever way.
Have a look at the class diagram for the strategy pattern. What is the relation between class 1 and class 2 based on the methods and the previous question?
Class 1 has-a class 2.
Class 2 has-a class 1.
Class 2 is-a class 1.
Class 1 is-a class 2.
Regarding the Observer Pattern, which statement is NOT correct?
Changes to either the subject or an observer will always affect the other.
We can add new observers at any time.
We never need to modify the subject to add new types of observers.
We can reuse subjects or observers independently of each other.
Loosely coupled designs can handle change because
they minimize the interdependency between objects.
they minimize the interfaces between objects.
they minimize the interactions between objects.
they minimize the inheritance between objects.
Which statement is correct regarding the State pattern?
Allows an object to alter its behaviour when its internal state changes
Allows (a group of) objects to be notified when some state changes
Changes the interface of one or more classes.
Simplifies the interface of a group of classes.
Which statement is correct regarding The Singleton Pattern
Ensures a class has only one instance and provides a global point of access to it
Ensures a class has only one instance for every class it uses it.
Ensures a class has only one instance per method
Ensures a class has only one instance as final.
