• Keine Ergebnisse gefunden

Design Patterns & Refactoring Bridge Oliver Haase

N/A
N/A
Protected

Academic year: 2022

Aktie "Design Patterns & Refactoring Bridge Oliver Haase"

Copied!
11
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Design Patterns & Refactoring

Bridge

Oliver Haase

HTWG Konstanz

‘A computer once beat me at chess, but it was no match to me at kick-boxing’ — Emo Philips

(2)

Description I

Classification: object based structural pattern

Purpose: decouple abstraction (interfaces) and implementation, such that both can evolve independently

(3)

Motivation

Scenario:

Provide more comfortable RemoteOpComminterface without modification of existing type hierarchy.

(4)

Motivation

Problem: Implementation classesTCPCommunication and UDPCommunication must be duplicated.

(5)

Motivation

(6)

Structure using Bridge Pattern

CommImpl sendImpl() receiveImpl() Communication

send(op, params): void receive(): Result

RemoteOpComm invoke(op, params): Result

impl.sendImpl(op,params);

TcpCommunication sendImpl(op, params): void receiveImpl(): Result

UdpCommunication sendImpl(op, params): void receiveImpl(): Result impl

return impl.receiveImpl();

send(op, params);

return receive();

Bridge Client

(7)

Implications

Please note that

the abstractions (left hand side) use only the functionality provided by classCommImpl. Additional functionality in the subclasses cannot be taken advantage of;

additional functionality in sub-interfaces must be achieved only through usage of the general functionality as contained in the root interface.

(8)

General Structure

Bridge Implementor

operationImpl() Abstraction

operation()

Specialization

impl.operationImpl();

ConcreteImplementorA operationImpl()

ConcreteImplementorB operationImpl() impl

Client

(9)

Description II

Members:

Abstraction(Communication):

defines interface of the abstraction

maintains reference toImplementor instance

Specialization(RemoteOpComm): extendsAbstractioninterface through usage of its operations

Implementor (CommImpl): defines interface for implementation classes (can differ from Abstractioninterface)

ConcreteImplementor(TcpCommunication): provides implementation of Implementorinterface

(10)

Description III

Interactions:Abstractiondelegates requests to Implementorobject Consequences:

loose coupling of abstraction and implementation Implementor object can be replaced at run-time

(11)

Implementation

Who decides when and how, what particular Implementor object to use?

1 Specializationobject, based on the params passed in at construction time.

Example:Collection object that gets initialized with small initial size uses LinearList implementation. LargeCollection object uses BTree implementation. (Note: Implementation can be dynamically replaced as the collection grows.)

2 Others decide→ creational patterns!

Specializationobject gets fed with factory or prototype Dependency injectionSpecializationobject gets passed in Implementor object byClient.

Referenzen

ÄHNLICHE DOKUMENTE

5 Textfield enabled see figure 3.4 In this field the user can enter the input 2 text for the hash value calculation.. The JCrypTool example text is loaded by default when the plug-in

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

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