Questions tagged [proxy-pattern]

A design pattern that provides a placeholder for another object to control access, reduce cost, and reduce complexity. One of the Gang of Four's structural design patterns.

A Proxy may

  • 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.

This is one of the Gang of Four's structural , first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".

More information is available on Wikipedia.

130 questions
464
votes
13 answers

How do the Proxy, Decorator, Adapter, and Bridge Patterns differ?

I was looking at the Proxy Pattern, and to me it seems an awful lot like the Decorator, Adapter, and Bridge patterns. Am I misunderstanding something? What's the difference? Why would I use the Proxy pattern versus the others? How have you used them…
Charles Graham
  • 24,293
  • 14
  • 43
  • 56
201
votes
10 answers

Differences between Proxy and Decorator Pattern

Can you give any good explanation what is the difference between Proxy and Decorator? The main difference I see is that when we assume that Proxy uses composition and Decorator uses aggregation then it seems to be clear that by using multiple (one…
Łukasz Rzeszotarski
  • 5,791
  • 6
  • 37
  • 68
185
votes
9 answers

What is copy-on-write?

I would like to know what copy-on-write is and what it is used for. The term is mentioned several times in the Sun JDK tutorials.
hhafez
  • 38,949
  • 39
  • 113
  • 143
30
votes
3 answers

What is the exact difference between Adapter and Proxy patterns?

As I understood both Adapter and Proxy patterns make two distinct/different classes/objects compatible with each for communication. And both of them are Structural patterns. I am getting that both of them are pretty much similar with each other. Can…
13
votes
3 answers

Difference between Proxy pattern and Virtual proxy pattern

I knew of the proxy pattern till now and recently read this article that says a virtual proxy is basically used to defer the Object Creation process of memory-intensive components thereby speeding up the Application. But after reading that article…
user20358
  • 14,182
  • 36
  • 114
  • 186
13
votes
3 answers

Java fallback pattern

I'm trying to find a nice way of implementing a service which relies on a third-party library class. I also have a 'default' implementation to use as fallback in case the library is unavailable or can not provide an answer. public interface Service…
13
votes
3 answers

How can the proxy pattern be used to replace a singleton?

This is in response to some comments in what is so bad about singletons There it was suggested that the proxy pattern can be used instead of a singleton to cache DB data. But I cannot see the advantage, and in fact the singleton seems more…
Dai Bok
  • 3,451
  • 2
  • 53
  • 70
12
votes
3 answers

Proxy a WebComponent's constructor that extends HTMLElement

So, in a library that I'm creating that uses custom elements, you obviously need to define the class in the CustomElementsRegistry before you may instantiate it. As of right now, this is being solved with a decorator: class Component extends…
ndugger
  • 7,373
  • 5
  • 31
  • 42
11
votes
2 answers

differences between proxy and dynamic proxy patterns

I'm trying to understand what are the differences between proxy and dynamic proxy patterns. from what I've read so far the only thing that I found out is that the proxy class byte-code is created during compile time and on dynamic proxy it's created…
Shai Zarzewski
  • 1,638
  • 3
  • 19
  • 33
11
votes
1 answer

Does Facade in Laravel implements Facade or Proxy Pattern?

As I understood, the Facade Pattern's intent is to provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. This can be used to simplify a number of…
Rezigned
  • 4,901
  • 1
  • 20
  • 18
8
votes
2 answers

Javascript Proxy and spread syntax, combined with console.log

So, I was playing around with Proxy objects and while trying to see how they mix with spread syntax and de-structuring, I stubled upon this weird behavior: const obj = { origAttr: 'hi' } const handler = { get(target, prop) { …
7
votes
2 answers

mixing constructor and apply traps on the Javascript Proxy object

I have a class that I'd like to apply a proxy to, observing method calls and constructor calls: Calculator.js class Calc { constructor(){} add(a, b) { return a+b; } minus(a, b) { return a-b; } } module.exports =…
Jarede
  • 3,310
  • 4
  • 44
  • 68
7
votes
1 answer

Use NSProxy in Swift 4.1

How to create an NSProxy subclass in Swift? Trying to add any of the init methods fails with error: "Super init can't be called outside of the initializer", or "Super init isn't called on all paths before returning from initializer" Using…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
7
votes
1 answer

Constructor call to proxy of a bound function

Suppose I have a function Foo, and I want objects constructed from it to have a bar property: function Foo() {} Foo.prototype.bar = 'baz' console.log('new Foo().bar: ' + new Foo().bar) new Foo().bar: baz Now suppose I bind Foo in some way. Bound…
effeffe
  • 2,821
  • 3
  • 21
  • 44
6
votes
2 answers

If In Proxy Pattern we have interface instead of actual concrete Subject in Proxy class is it equivalent to Decorator Pattern

Proxy pattern delegates the request to the Real subject after doing some additional processing like applying checks if request needs to be processed or not based on may be some credential checks. It has class diagram as below Proxy class has a…
nits.kk
  • 5,204
  • 4
  • 33
  • 55
1
2 3
8 9