• Keine Ergebnisse gefunden

Design Patterns & Refactoring Introduction to Refactoring Oliver Haase

N/A
N/A
Protected

Academic year: 2022

Aktie "Design Patterns & Refactoring Introduction to Refactoring Oliver Haase"

Copied!
13
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Design Patterns & Refactoring

Introduction to Refactoring

Oliver Haase

HTWG Konstanz

(2)

What is Refactoring?

Definition (of the noun)

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

Definition (of the verb)

To restructure software by applying a series of refactorings without changing its observable behavior. (Martin Fowler)

(3)

Definition – Key Points

make software structure easier: compare with performance optimizations that

don’t change functionality,

but usually make softwareharderto understand!

without changing behavior: user (end user or other software) cannot tell that implementation has changed.

No Refactoring Without Thorough Unit Tests!

(4)

Definition – Key Points

make software structure easier: compare with performance optimizations that

don’t change functionality,

but usually make softwareharderto understand!

without changing behavior: user (end user or other software) cannot tell that implementation has changed.

No Refactoring Without Thorough Unit Tests!

(5)

Metaphor of the Two Hats

Software development should consist of distinguishable phases of addition of new functionality andrefactoring:

When adding new functionality, don’t refactor existing code.

When refactoring, don’t change existing behavior.

A developer might swap hats very frequently, but should always be aware of which hat she is currently wearing.

(6)

Why Should You Refactor?

Without refactoring, code will decay

more often than not, code additions lead to redundancy!

refactoring as a means to periodically clean up code Refactoring makes the code easier to understand Refactoring helps you find bugs

Refactoring helps you program faster

(7)

When Should You Refactor?

Should you schedule two weeks of refactoring every other month of development?

You don’t decide to refactor, you refactor because you want to do something else, and refactoring helps you do the other thing.

(8)

When Should You Refactor?

Should you schedule two weeks of refactoring every other month of development?

You don’t decide to refactor, you refactor because you want to do something else, and refactoring helps you do the other thing.

(9)

The Rule of Three

Three strikes and you refactor.

1 Just do it.

2 Wince at duplication, duplicate anyway.

3 Refactor.

(10)

The Rule of Three

Three strikes and you refactor.

1 Just do it.

2 Wince at duplication, duplicate anyway.

3 Refactor.

(11)

What Do I Tell My Manager?

Many managers don’t appreciate refactoring per se

but: refactoring is a necessary part of the development process

⇓ Don’t tell.

(12)

What Do I Tell My Manager?

Many managers don’t appreciate refactoring per se

but: refactoring is a necessary part of the development process

⇓ Don’t tell.

(13)

Problems with Rectoring

Databases: Data schemas that applications are tightly coupled to are hard to change → Refactoring of databases is an own research area.

Changing Interfaces:

Minimizepublishedinterfaces, i.e. those whose users you cannot change.

Don’t publish interfaces prematurely.

Loosen code ownership so that unpublished interfaces can be changed.

Referenzen

ÄHNLICHE DOKUMENTE

A method satisfies Modular Continuity if, in the software architectures that it yields, a small change in the problem specification will trigger a change of just one module, or

[Refactoring is] a change made to the internal structure of the software to make it easier to understand and cheaper to modify without changing its observable

Implementor (CommImpl): defines interface for implementation classes (can differ from Abstraction interface). ConcreteImplementor (TcpCommunication): provides implementation

knows which subsystem classes are responsible for which requests delegates client requests to respective subsytem

Purpose: Define method for object creation in abstract class, leave actual creation to concrete subclasses.. Also known as:

When an RMI server object is exported, the runtime system (Java virtual machine) creates a dynamic proxy (RMI stub) that implements the respective remote interface, and forwards

Similar structures, in both cases indirect access to actual object via upstream object. in both cases, upstream object maintains reference to actual object (subject) and

In this paper, we concentrate on features that measure the first two aspects of readability (linguistic and content-wise appropriate- ness). A special challenge in our