Chapter 4 - Design Patterns Flashcards

1
Q

Which kinds of Patterns are there?

A

Idioms: Usage of programming language features, Design Patterns: teams of interacting objects and classes, Architecture Patterns: building blocks of software architecture

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

What is good Class Design?

A

minimize visibility of classes and members (private as default), minimize mutability, single responsibility (class should only do one thing), naming (simple & expressive names)

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

What is SOLID?

A

SRP, OCP, LSP, ISP, DIP

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

What is SRP?

A

Single Responsibility Principle: separation of concerns, changes to a class should have only a single reason

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

What is OCP?

A

Open-Closed Principle: classes closed for modifications, but open for extensions

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

What is LSP?

A

Liskov Substitution Principle: derived class must fulfill the contract of its base class

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

What is ISP?

A

Interface Segregation Principle: clients should not depend on interfaces they don’t need, if possible many small interfaces instead of one big

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

What is DIP?

A

Dependency Inversion Principle: high level components should not depend on low-level components, changes in lower level must not impact higher layers

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

what is the motivation of design patterns?

A

reuse is a main incentive, design can be best reused of all thing

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

Name types of Design Patterns

A

creational patterns: encapsulate creation process, Structural patterns: compositions of classes and objects, Behavioral Patterns: how do objects work together? collaboration patterns

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

Define the Singleton Pattern

A

ensure that there is only a single instance of a class, provides global access point to this instance

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

Define Factory Method

A

defines interface for creating an object, subclass decides what objects are being created

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

Define Abstract Factory

A

provides an interface for creating families of related or dependent objects without specifying their concrete classes

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

Define Adapter

A

convert interface of a class into an interface expected by clients (also known as Wrapper)

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

Define Bridge

A

decouple abstraction from its implementation such that both can vary independently, avoid strong coupling between abstraction and implementation

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

Define Decorator

A

attach additional responsibilities to an object dynamically, decorator delegates operations to component object

17
Q

Define Observer

A

changing the state of an objects notifies all dependent so they can update, subject knows all its observers and notifies them or Observer defines updating interface

18
Q

what is FCoI?

A

Favour Composition over Inheritance: erwendet man Funktionalität wieder durch das Ableiten von einer Klasse, so ist die Subklasse abhängig von der Elternklasse. Dies macht ein System in vielen Fällen unnötig komplex, schlechter testbar und erschwert das Austauschen von Funktionalität zur Laufzeit.Bei der Komposition verwendet eine Klasse eine andere. Verwendet man dazu eine klar definierte Schnittstelle, fördert das die Entkopplung. Auch können verschiedene Implementationen einfach ausgetauscht werden. Bevor man sich also der Liskov Substitution stellt, fordert Favour Composition over Inheritance, sich die Frage zu stellen, ob man der Komposition nicht Vorrang geben kann.