• Keine Ergebnisse gefunden

Design Patterns and Refactoring Introduction Oliver Haase

N/A
N/A
Protected

Academic year: 2022

Aktie "Design Patterns and Refactoring Introduction Oliver Haase"

Copied!
10
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Design Patterns and Refactoring

Introduction

Oliver Haase

HTWG Konstanz

Oliver Haase (HTWG Konstanz) Design Patterns and Refactoring 1 / 9

(2)

Literature

Design Patterns

Erich Gamma et al.Design Patterns: Elements of Reusable Object-Oriented Software1, Addison–Wesley, 1994, ISBN 78-0201633610.

Elisabeth Freeman et al. Head First Design Patterns, O’Reilly, 2004, ISBN 978-0596007126.

Refactoring

Martin Fowler et al. Refactoring: Improving the Design of Existing Code, Addison–Wesley, 1999, ISBN 978-0201485677.

(3)

Design Patterns — Definition

Design Pattern:

“Each [design] pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem” — Christopher Alexander, 1977.

Christopher Alexander: born 1936 in Vienna

studied mathematics and architecture (Cambridge) received PhD in architecture (Harvard)

professor for architecture (UoC, Berkeley) known as the founder of design patterns

Oliver Haase (HTWG Konstanz) Design Patterns and Refactoring 3 / 9

(4)

Design Patterns — Goals

fast to develop, clean solution through solution reuse

simplified maintenance through clean structures and deja vu effects improved extensibility through anticipatory design

(partly) opportunity for code generation or language support (e.g. singleton pattern)

(partly) opportunity for class libraries (e.g. observer pattern)

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler.

(5)

Design Patterns — Goals

fast to develop, clean solution through solution reuse

simplified maintenance through clean structures and deja vu effects improved extensibility through anticipatory design

(partly) opportunity for code generation or language support (e.g.

singleton pattern)

(partly) opportunity for class libraries (e.g. observer pattern)

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler.

Oliver Haase (HTWG Konstanz) Design Patterns and Refactoring 4 / 9

(6)

Design Patterns — Principles of Reusable Design

According to GoF, there are two fundamental principles of reusable software design (that also underly most if not all patterns):

Principle of reusable software design

Program against an interface, not an implementation.

2nd principle of reusable software design Prefer composition over inheritance.

“Computer Science is the discipline that believes all problems can be solved with one more layer of indirection.” — Dennis DeBruler.

(7)

Design Patterns — Principles of Reusable Design

Key motivation behind both design principles:

Holy Grail of reusable software design

Avoid code dependencies to the largest extent possible.

Oliver Haase (HTWG Konstanz) Design Patterns and Refactoring 6 / 9

(8)

Design Patterns — Categorization

GoF categorize design patterns based on two criteria:

1 Purpose

creational: patterns for object creation

structural: patterns that compose classes and objects

behavioral: patterns that distribute responsibility for behavior across classes and objects, and make them interact

2 Scope

class based: based on relationships between classes, mainly inheritance object based: based on relationships between objects

(9)

Design Patterns — Categorization

creational structural behavioral class factory method adapter interpreter

based (class based) template method

object abstract factory adapter command based builder (object based) observer

prototype bridge visitor

singleton decorator iterator

facade memento

flyweight strategy composite mediator

proxy state

chain of responsibility

Oliver Haase (HTWG Konstanz) Design Patterns and Refactoring 8 / 9

(10)

What’s Next?

“The way to get started is to quit talking and begin doing” — Walt Disney.

Referenzen

ÄHNLICHE DOKUMENTE

 Programm kann direkt auf jede Zielmaschine portiert werden, die einen Interpretierer für die Sprache

Lesen Sie die Zahlen a und b von der Tastatur ein, weisen Sie das Ergebnis der obigen Berechnung einer boolschen Variablen istTeiler zu und geben Sie den Wert dieser Variablen auf

A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior..

Communication is centralized in broker (mediator) object Broker is responsible to preserve consistency. Broker is single point of failure and scalability bottle-neck Communication

plain text documents, even though its functionality is applicable to other document types as well;. Difficult to use document mock-up

Receiver must allow command object to restore receiver’s original state. Client stores all executed commands in a

Divide object state into intrinsic and extrinsic state, such that there is only a small number of distinct objects with different intrinsic states.. Share these

Element: defines an accept operation with a Visitor as argument ConcreteElement: implements the accept operation, usually by calling the visitor’s appropriate visit