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
3
votes
1 answer

What could be a "least bad implementation" for an iterator over a proxied container?

Context I was trying to implement a nD array like container. Something that would wrap an underlying sequence container and allow to process it as a container of containers (of...): arr[i][j][k] should be a (eventually const) reference for _arr[(((i…
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
3
votes
1 answer

Facade with two services inside and dependency injection - design pattern approach

I want to create Facade class to handle few operations on two services. For contacting those services I've got proxy classes. Having abstract Proxy and derived proxy per service - how can I create this part of architecture, to avoid Resolving in…
Saint
  • 5,397
  • 22
  • 63
  • 107
3
votes
2 answers

How do I dynamically implement the Proxy Pattern?

I'm revisiting my class tracking (dirty logic), which I wrote last year. Currently I have an uber base class that deals with all the state tracking, but each property whos values I need to track needs to stick to the standard get { return _x; } set…
djdd87
  • 67,346
  • 27
  • 156
  • 195
3
votes
2 answers

Dependency Injection, Lazy loading, Proxy and circular dependency

This is a language independent question but I write the sample codes in PHP. We have a two classes : User class UserRepository class UserRepository class deals with the interaction with DB and loading the required User in to a User object and…
2
votes
1 answer

Using inheritance over composition in a proxy-pattern

I'm just curious why all examples of proxy-pattern written in Python are using composition over inheritance? If proxy class should implement all of the methods of original class, isn't it easier to inherit proxy from original and just overwrite…
2
votes
1 answer

Virtual functions in Proxy pattern in C++

If I have a proxy pattern Class A and proxy for that is Class PrxA. Question1 If I define few functions as virtual in A are those supposed to be defined as virtual even in PrxA? Now if Class B : public A { ///code } I believe the proxy class…
leonidus
  • 71
  • 1
  • 4
2
votes
2 answers

Why are _initializing and isTopLevelCall variables used in Initializable contract of Openzeppelin?

This is abstract contract in the context of Proxy pattern: abstract contract Initializable { bool private _initialized; bool private _initializing; modifier initializer() { require(_initializing || !_initialized, "Initializable:…
Cengo
  • 93
  • 5
2
votes
3 answers

What is the name of this pattern? (answer: Remote Proxy)

Consider a class OriginalClass that might or might not be available on runtime. OriginalClass has a method doSomething which should be executed if its class is available. A way of solving this is creating a class that also has a doSomething method…
hpique
  • 119,096
  • 131
  • 338
  • 476
2
votes
1 answer

In microservice architecture, what is the difference between proxy pattern and aggregator composition pattern?

In its simplest form, Aggregator invokes multiple services to achieve the functionality required by the application. Proxy is a variation of Aggregator. In this case, no aggregation needs to happen on the client but a different microservice may be…
2
votes
0 answers

How .NET DispatchProxy works/implemented?

I was looking at a way to implement a class Proxy in .NET (Core) and found out there is actually an implementation in the framework called DispatchProxy (source code). When I looked at the source code, it is actually implemented here at…
Luke Vo
  • 17,859
  • 21
  • 105
  • 181
2
votes
0 answers

How do I extract type information from Proxy in a type family for a GADT?

I have the following snippet: {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeInType #-} import Data.Proxy data Foo where FooInt :: Foo FooProxy :: IsEnum e ~ True => Proxy e -> Foo type family…
2
votes
2 answers

Ruby: Proxy pattern, reducing method calls

How do I proxy the ruby logger and keep performance? So, we have an requirement at work, quite reasonable. When a program is sent the signal HUP the log is flushed and restarted. class LocalObject attr_accessor :logger def initialize…
Daniel
  • 7,006
  • 7
  • 43
  • 49
2
votes
1 answer

Understanding Proxy Pattern in C#

Suppose if I am trying to access a method of a class through some other class like this class SuperClass { public interface ISubject { void Print(); } private class Subject : ISubject { …
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85
2
votes
0 answers

Arithmetic type proxy

Background I'm working on C++11 JSON mapping classes to introduce syntactically intuitive and safe objects which can serialize/deserialize itself into JSON representation. The Question I need to provide a good proxy for arithmetic types (mainly for…
Rames
  • 918
  • 11
  • 27
2
votes
3 answers

cache using functional callbacks/ proxy pattern implementation scala

How to implement cache using functional programming A few days ago I came across callbacks and proxy pattern implementation using scala. This code should only apply inner function if the value is not in the map. But every time map is reinitialized…
1 2
3
8 9