Proxy Pattern (et Relata) (seen from someone still living in the '70, the '80 and, partly, in the '90)

Similar documents
Introduction to Software Engineering: Object Design I Reuse & Patterns

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Proxy Design Pattern

Coordination Patterns

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt.

26.1 Introduction Programming Preliminaries... 2

Model-Driven Design Using Business Patterns

USB. USB Sticks in Design und Qualität

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt.

Design Patterns V Structural Design Patterns, 2

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Summary of the course lectures

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt.

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

1. Übungsblatt. Vorlesung Embedded System Security SS 2017 Trusted Computing Konzepte. Beispiellösung

Das Seminar kann zur Vorbereitung auf die Zertifizierung als Microsoft Certified Solutions Developer (MCSD): SharePoint Applications genutzt werden.

Standardizing the Geospatial Farm

Auskunftsbegehren gemäß Art 15 DSGVO (Facebook Version englisch) - V1.0

Search Engines Chapter 2 Architecture Felix Naumann

Material and some slide content from: - GoF Design Patterns Book. Design Patterns #1. Reid Holmes. Lecture 11 - Tuesday October

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Modern and Lucid C++ for Professional Programmers. Week 15 Exam Preparation. Department I - C Plus Plus

What s New? SAP HANA SPS 07 SAP HANA tailored data center integration. SAP HANA Product Management November, 2013

Issues in Distributed Architecture

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

The Strategy Pattern Design Principle: Design Principle: Design Principle:

The Proxy Pattern. Design Patterns In Java Bob Tarr

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Adapter pattern. Acknowledgement: Freeman & Freeman

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Developing Microsoft Azure Solutions MOC 20532

Ulrich Stärk

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

TI-No. 4002TI05.doc PAGE NO. : 1/1. Settings after Installation of the Firmware Version 74

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

SDC Design patterns GoF

Scripted Components: Problem. Scripted Components. Problems with Components. Single-Language Assumption. Dr. James A. Bednar

Scripted Components Dr. James A. Bednar

M/R for MR. Bild. Market Research powered by Hadoop. nurago - applied research technologies 1. nurago - applied research technologies

Einsatz von Komponenten in JEE am Beispiel von IMIXS

Übungsstunde: Informatik 1 D-MAVT

Contents. 1) Introduction to clustering 2) Partitioning Methods K-Means K-Medoid Choice of parameters: Initialization, Silhouette coefficient

Enabling Flexibility in Process-Aware Information Systems

Design Patterns Reid Holmes

Object-Process Methodology

Virtual Memory. Physical Addressing. Problem 2: Capacity. Problem 1: Memory Management 11/20/15

Dwg viewer free download vista. Dwg viewer free download vista.zip

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

Fortran? C++? Egal! Ein guter Programmierer kann Spaghetti-Code in jeder Sprache schreiben!

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

Communication. Distributed Systems Santa Clara University 2016

Introduction to Design Patterns

Verkürze & optimiere Softwareentwicklungszyklen mit Application Performance Monitoring und DevOps

Einführung in die Kognitive Ergonomie

LilyPond Automated music formatting and The Art of Shipping

Übungsfragen für den Test zum OMG Certified UML Professional (Intermediate) Download

FXD A new exchange format for fault symptom descriptions

Component vs. Module

Mobile Transport Layer

What s New? SAP HANA SPS 07 Fuzzy Search (Delta from SPS 06 to SPS 07) SAP HANA Product Management November, 2013

Structured Peer-to-Peer Services for Mobile Ad Hoc Networks

COPYRIGHTED MATERIAL. Table of Contents. Foreword... xv. About This Book... xvii. About The Authors... xxiii. Guide To The Reader...

The COSA Framework. A Cognitive System Architecture with its implementation based on a CORBA-wrapped SOAR process

Design Patterns Revisited

SmartNode 4900 IpChannel Bank

Heresies and Dogmas in Software

Using Design Patterns in Java Application Development

1 enum class -- scoped and strongly typed enums

X.media.publishing. Multimedia Systems. Bearbeitet von Ralf Steinmetz, Klara Nahrstedt

TDM+VoIP Smart Media Gateway

AC500. Application Note. Scalable PLC for Individual Automation. AC500-S safety PLC - Overview of changes in Automation Builder 2.1.x and 2.0.

CS 251 Intermediate Programming Methods and Classes

Egon Borger (Pisa) Capturing Design Pattern Abstractions by ASMs

xpipe Reception of DICOM Data from any Sender via the Internet

Week - 01 Lecture - 04 Downloading and installing Python

COPYRIGHT: NACHGEDRUCKT ODER SONST REPRODUZIERT WERDEN (Z. B. AUF CD-ROM ODER IM INTERNET).

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

C1-MFD3-R3. Compatible with navigation systems Volkswagen RNS510, RNS810 Skoda Columbus Seat Trinax

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Design Patterns in C++

(D)COM Microsoft s response to CORBA. Alessandro RISSO - PS/CO

TriCore TM 1 Pipeline Behaviour & Instruction Execution Timing

Copyright (C) Fujitsu Siemens Computers GmbH 2008 All rights reserved

Design and implementation of Virtual Security Appliances (VSA) for SME

What s New? SAP HANA SPS 07 Administration & Monitoring (Delta from SPS 06 to SPS 07) SAP HANA Product Management November, 2013

SoberIT Software Business and Engineering Institute. SoberIT Software Business and Engineering Institute. Contents

1. SQL definition SQL is a declarative query language 2. Components DRL: Data Retrieval Language DML: Data Manipulation Language DDL: Data Definition

Using extensible metadata definitions to create a vendor independent SIEM system

Data Warehousing. Metadata Management. Spring Term 2016 Dr. Andreas Geppert Spring Term 2016 Slide 1

Continuous Delivery. für Java Anwendungen. Axel Fontaine Software Development Expert

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

DESIGN PATTERN - INTERVIEW QUESTIONS

Design Patterns. An introduction

SAP HANA Revision Strategy. SAP HANA Product Management May 2014

The activities described in these upgrade instructions may only be performed by engineers or maintenance/technical staff.

Advanced Topics in Operating Systems

Status of the "H.325 Project"

Transcription:

Proxy Pattern (et Relata) (seen from someone still living in the '70, the '80 and, partly, in the '90) 1

Proxy Pattern Pattern Name and Classification (Kategorisierung) Intent (Zweck) Motivation/ Forces (Problem/Kontext/Umfeld) Implementation (Lösung/Umsetzung) Structure Applicability (Szenario/Verwendung) Pros & Cons (Vorteilen/Nachteilen) Related Patterns (Verweise) Code examples 2

Pattern Name and Classification Pattern Name: Proxy Pattern (Stellvertreter) Classification: Structural Pattern (structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.) 3

Intent Provide a surrogate or placeholder for another object to control access to it. Use an extra level of indirection to support distributed, controlled, or intelligent access. Add a wrapper and delegation to protect the real component from undue complexity. 4

Motivation/Problem You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client. 5

Implementation Design a surrogate, or proxy, object that: instantiates the real object the first time the client makes a request of the proxy remembers the identity of this real object and forwards the instigating request to this real object. Then all subsequent requests are simply forwarded directly to the encapsulated real object. 6

Implementation Check list Identify the leverage or "aspect" that is best implemented as a wrapper or surrogate. Define an interface that will make the proxy and the original component interchangeable. Consider defining a Factory that can encapsulate the decision of whether a proxy or original object is desirable. The wrapper class holds a pointer to the real class and implements the interface. The pointer may be initialized at construction, or on first use. Each wrapper method contributes its leverage, and delegates to the wrappee object. 7

Structure By defining a Subject interface, the presence of the Proxy object standing in place of the RealSubject is transparent to the client. 8

Applicability There are four common situations in which the Proxy pattern is applicable. 1)VirtualProxy: A virtual proxy is a placeholder for "expensive to create" objects. The real object is only created when a client first requests/accesses the object. 2)RemoteProxy: A remote proxy provides a local representative for an object that resides in a different address space. This is what the "stub" code in RPC and CORBA provides. 3)ProtectionProxy: A protective proxy controls access to a sensitive master object. The "surrogate" object checks that the caller has the access permissions required prior to forwarding the request. (e.g.: www-proxy) 4)SmartProxy: A smart proxy interposes additional actions when an object is accessed. Typical uses include: Counting the number of references to the real object so that it can be freed automatically when there are no more references (aka smart pointer), Change or augment the behavior of the instantiated object (useful with classes libraries we do not have the source code). Checking that the real object is locked before it is accessed to ensure that no other object can change it. 9

Pros & Cons Pro: As seen in Applications, with a Proxy we can implement aspects that are not related with the proper logic of the real object (such as security,logging, pooling caching and the likes) Cons: For each method in the realclass we have to implement a coresponding method in the proxy (possible solution: Dynamic Proxy) 10

Related Patterns Adapter provides a different interface to its subject. Proxy provides the same interface as its subject (or a subset, in the case of ProtectionProxy). Decorator provides an enhanced interface (adds one or more responsibility), whereas a proxy controls access to an object. Decorator and Proxy have different purposes but similar structures. Both describe how to provide a level of indirection to another object, and the implementations keep a reference to the object to which they forward requests. 11

Code examples C++: Proxy in C++: Before and after Java:Proxy Pattern Java Example 12

Design Patterns Considered Harmful (Oh NO... NOT AGAIN!) 13

Design Patterns Considered Harmful First, let me quote Prof. Amrhein's slide #3s from DesignPatternEinfuehrung.pdf: Design Pattern sind unabhängig von der konkreten Programmiersprache. Das ermöglicht, dass man zunächst abstrakt über mögliche Lösungen sprechen kann. Damit kann auf hohem Abstraktions-Niveau über verschiedene Alternativen diskutiert werden, also ohne eine konkrete Lösung (Programmcode). And slide #4: Entwickler konnen durch das Kennen vieler Design Pattern dazu verleitet werden, moglichst viele Pattern zu verwenden und dabei ubersehen, dass in ihrem Fall vielleicht eine einfachere, elegantere Losung ohne den Einsatz von Design Pattern sinnvoller gewesen ware. Design Pattern konnen den Code unnotig aufblahen, da durch das Verwenden des Pattern (ev. unnotigerweise) ein allgemeineres Problem gelost wird. Entwurfsmuster garantieren nicht, dass der Entwurf gut ist. Insofern ist die Anwendung zu vieler oder ungeeigneter Entwurfsmuster ein Antimuster. 14

Design Patterns Considered Harmful 15

Design Patterns Considered Harmful Then let's see what Wikipedia says (This has always bothered me): - A design pattern is not a finished design that can be transformed directly into source or machine code. - By definition, a pattern must be programmed anew into each application that uses it. Since some authors see this as a step backward from software reuse as provided by components, researchers have worked to turn patterns into components.[...] Criticism The concept of design patterns has been criticized in several ways. The design patterns may just be a sign of some missing features of a given programming language (Java or C++ for instance). Peter Norvig demonstrates that 16 out of the 23 patterns in the Design Patterns book (that is primarily focused on C++) are simplified or eliminated (via direct language support) in Lisp or Dylan.[24] Related observations were made by Hannemann and Kiczales who implemented several of the 23 design patterns using an aspect-oriented programming language (AspectJ) [ ].[25] See also Paul Graham's essay "Revenge of the Nerds".[26] Moreover, inappropriate use of patterns may unnecessarily increase complexity.[27] [wikipedia: http://en.wikipedia.org/wiki/software_design_pattern] 16

Design Patterns Considered Harmful Paul Graham's essay "Revenge of the Nerds" (2002: considerations still valid!) Greenspun's Tenth Rule: Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp. If you try to solve a hard problem, the question is not whether you will use a powerful enough language, but whether you will (a) use a powerful language, (b) write a de facto interpreter for one, or (c) yourself become a human compiler for one. [ ] For example, in the OO world you hear a good deal about "patterns". I wonder if these patterns are not sometimes evidence of case (c), the human compiler, at work. When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I'm using abstractions that aren't powerful enough-- often that I'm generating by hand the expansions of some macro that I need to write. [source: http://www.paulgraham.com/icad.html] 17

Design Patterns Considered Harmful References: http://perl.plover.com/yak/design/samples/slide001.html http://c2.com/cgi/wiki?designpatternsconsideredharmful http://www.perlmonks.org/?node_id=133399 http://blog.codinghorror.com/head-first-design-patterns/ http://blog.codinghorror.com/rethinking-design-patterns/ http://www.paulgraham.com/icad.html http://www.norvig.com/design-patterns/ http://www.dadhacker.com/blog/?p=1274 18

Design Patterns Considered Harmful "All problems in computer science can be solved by another level of indirection, except of course for the problem of too many indirections." David Wheeler(*) (*) another immortal quote from the late Prof. Wheeler is Compatibility means deliberately repeating other people's mistakes. 19