Bridge pattern
Questa voce sull'argomento programmazione è solo un abbozzo.
Contribuisci a migliorarla secondo le convenzioni di Wikipedia.
Il bridge pattern è un design pattern (modello di progettazione) della programmazione ad oggetti che permette di separare l'interfaccia di una classe (che cosa si può fare con la classe) dalla sua implementazione (come lo fa). In tal modo si può usare l'ereditarietà per fare evolvere l'interfaccia o l'implementazione in modo separato.
Struttura
Esempio in Java
Il seguente programma stamperà:
API1.circle at 1.000000:2.000000 radius 7.5000000 API2.circle at 5.000000:7.000000 radius 27.500000
/** "Implementor" */ interface DrawingAPI { public void drawCircle(double x, double y, double radius); } /** "ConcreteImplementor" 1/2 */ class DrawingAPI1 implements DrawingAPI { public void drawCircle(double x, double y, double radius) { System.out.printf("API1.circle at %f:%f radius %f\n", x, y, radius); } } /** "ConcreteImplementor" 2/2 */ class DrawingAPI2 implements DrawingAPI { public void drawCircle(double x, double y, double radius) { System.out.printf("API2.circle at %f:%f radius %f\n", x, y, radius); } } /** "Abstraction" */ abstract class Shape { protected DrawingAPI drawingAPI; protected Shape(DrawingAPI drawingAPI){ this.drawingAPI = drawingAPI; } public abstract void draw(); // low-level public abstract void resizeByPercentage(double pct); // high-level } /** "Refined Abstraction" */ class CircleShape extends Shape { private double x, y, radius; public CircleShape(double x, double y, double radius, DrawingAPI drawingAPI) { super(drawingAPI); this.x = x; this.y = y; this.radius = radius; } // low-level i.e. Implementation specific public void draw() { drawingAPI.drawCircle(x, y, radius); } // high-level i.e. Abstraction specific public void resizeByPercentage(double pct) { radius *= pct; } } /** "Client" */ class BridgePattern { public static void main(String[] args) { Shape[] shapes = new Shape[] { new CircleShape(1, 2, 3, new DrawingAPI1()), new CircleShape(5, 7, 11, new DrawingAPI2()), }; for (Shape shape : shapes) { shape.resizeByPercentage(2.5); shape.draw(); } } }
Voci correlate
- Design pattern
Altri progetti
Altri progetti
- Wikimedia Commons
- Wikimedia Commons contiene immagini o altri file su bridge pattern
V · D · M | |
---|---|
Creazionali | Abstract factory · Builder · Factory · Prototype · Singleton |
Strutturali | Adapter · Bridge · Composite · Container pattern · Decorator · Façade · Flyweight · Proxy |
Comportamentali | Chain-of-responsibility · Command · Interpreter · Iterator · Mediator · Memento · Observer · State · Strategy · Template method · Visitor |
Pattern di concorrenza | Active object · Balking · Binding properties · Double-checked locking · Event-based asynchronous · Guarded suspension · Join · Lock · Monitor · Proactor · Reactor · Read write lock · Scheduler · Thread pool · Thread-local storage |
Pattern architetturali | Front controller · Interceptor · MVC · n-tier · Specification · Publish–subscribe · Naked objects · Service locator · Active record · Identity map · Data Access Object · Data transfer object · ADR · Inversione del controllo |
Altri pattern | Blackboard · Business delegate · Composite entity · Dependency injection · Intercepting filter · Lazy loading · Mock object · Null object · Object pool · Servant · Twin · Type tunnel |
Libri | Design Patterns · Enterprise Integration Patterns |
Persone | Christopher Alexander · Erich Gamma · Ralph Johnson · John Vlissides · Grady Booch · Kent Beck · Ward Cunningham · Martin Fowler · Robert Martin · Jim Coplien · Douglas Schmidt · Linda Rising |
Comunità | The Hillside Group · The Portland Pattern Repository |
Portale Informatica: accedi alle voci di Wikipedia che trattano di informatica