1 / 15

Proxy Pattern

Proxy Pattern. Vorlesung Design Patterns Sieglinde Heinrich 21.04.2004 sh34@hdm-stuttgart.de. Abgrenzung. Absicht Stellvertreter für ein anderes Objekt bietet Kontrolle über Objekt- Erzeugung und –Zugriff Motivation kostspielige Objekt- Erzeugung verzögern (zB: große Bilder)

oihane
Télécharger la présentation

Proxy Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Proxy Pattern Vorlesung Design Patterns Sieglinde Heinrich 21.04.2004 sh34@hdm-stuttgart.de

  2. Abgrenzung

  3. Absicht • Stellvertreter für ein anderes Objekt • bietet Kontrolle über Objekt- Erzeugung und –Zugriff Motivation • kostspielige Objekt- Erzeugung verzögern (zB: große Bilder) • Remote Objekt • Sicherheitsfunktion • Cache Idee • Bild- Stellvertreter (Proxy) verwenden • Bild- Stellvertreter verhält sich aus Client- Sicht wie Bild • Bild- Stellvertreter erzeugt Bild bei Bedarf

  4. Proxy Pattern - Schema

  5. Konkretes Beispiel

  6. public interface IVehicle { public void start(); public void stop(); public void forward(); public void reverse(); public String getName(); }

  7. public class Car implements IVehicle { private String name; public Car(String name) {this.name=name;} public void start() { System.out.println("Car " + name + " started"); } public void stop() {…} public void forward() {…} public void reverse() {…} public String getName() {…} }

  8. public class VehicleProxy implements IVehicle { private IVehicle v; public VehicleProxy(IVehicle v) { this.v=v; } public void start() { System.out.println("VehicleProxy: Begin of start()"); v.start(); System.out.println("VehicleProxy: End of start()"); } public void stop() {…} public void forward() {…} public void reverse() {…} public String getName() {…} }

  9. public class Client { public static void main(String[] args) { new Client(); } public Client() { IVehicle c = new Car("Audi A7"); IVehicle v = new VehicleProxy(c); v.start(); v.forward(); v.stop(); } }

  10. Fall- Beispiel Protection Proxy (Zugriffskontrolle)  Remote  Zugriff  Ressourcen

  11. Lösung Kommunikation über den Proxy • lokalisiert entferntes Objekt und „kommuniziert“ mit ihm • Authentifikationsprüfung • unötige Zugriffe werden verhindert zufrieden stellendes Ergebnis

  12. Konsequenzen • Der Remote-Proxy • Der Schutz-Proxy übernimmt zusätzliche Sicherheitsfunktionen • Der Cache-Proxy speichert dieo Daten einer Komponente zwischen

  13. Implementation (technisch) Verantwortlichkeiten dem Stellvertreter zuweisen Abstrakte Basisklasse einführen Funktionen des Stellvertreters implementieren Original und Client von Verantwortlichkeit lösen Original und Proxy verbinden Client vom Original lösen

  14. Weitere Proxy Varianten • Virtueller Proxy • Schutz- Proxy • Synchronisierungs- Proxy • Remote- Proxy • Firewall- Proxy • Counting- Proxy • Cache- Proxy

  15. Vielen Dank

More Related