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
0
votes
0 answers

Proxy pattern in Javascript without inbuilt Proxy class

I want to intercept requests to Object A and log some message and forward the request back to Object A Es6 proxies and reflect would be a good use case for this, but I’ll be taking a huge performance hit. I want to implement a proxy on my own, what…
Eshwar NE
  • 113
  • 1
  • 1
  • 8
0
votes
0 answers

How do I fix a proxy when the base interfaces are not shared?

I have inherited a project that has a ton of duplicate Repositories and duplicate Units of Work objects. For instance: namespace MyProject.Domain.Plant.Repositories { public interface IPlantEmployeeRepository : IRepository { …
Keith Barrows
  • 24,802
  • 26
  • 88
  • 134
0
votes
1 answer

How to implement proxy pattern involving async call?

How to implement proxy pattern involving async call? Just for example, if I want to get something, I will first check if the object resides in memory, if it's not, then I will make http request to retrieve it (which is async call). Customer…
janetsmith
  • 8,562
  • 11
  • 58
  • 76
0
votes
1 answer

InvocationHandler in Kotlin

I'm reading Head First: Design Patterns (2nd ed) and I followed the code sample but instead of using Java, I used Kotlin. Currently, I'm in a chapter tackling about proxy protection pattern and having difficulty to run it with Kotlin. Please see the…
jjz
  • 2,007
  • 3
  • 21
  • 30
0
votes
0 answers

Typescript Proxying a function to extend accepted arguments or their types

I'm trying to have a class which partly acts as a Proxy wrapper around some other class, allowing the other class methods to be modified and accept either extra arguments or to change their type. Let's imagine I have: class MainClass { …
NinGen ShinRa
  • 651
  • 5
  • 16
0
votes
1 answer

How to add a getter for a new property with a Proxy in Typescript

I have an object that I'd like to add a new property to: this.exampleConfig = new Proxy(config, { set: (obj, prop, value) => { ... } } I'm using this in an angular application, and currently have a exampleConfig.myProperty. I'd…
Frazer Kirkman
  • 1,003
  • 1
  • 14
  • 23
0
votes
1 answer

Is this an Adapter or a Proxy?

You work on a legacy app which has a static class UserDataAccess: public static class UserDataAccess { public static void AddUser(User user) { // Insert user into DB } } which is used by a UserService class: public class…
Don Box
  • 3,166
  • 3
  • 26
  • 55
0
votes
1 answer

How to proxify the instanciation of array with literal notation []

I can detect new instance made via Array() or new Array(). But what about [] ? const originalArray = Array; Array = new Proxy(Array,{ construct(target, args) { console.log('new array'); const newArray =…
8HoLoN
  • 1,122
  • 5
  • 14
0
votes
2 answers

TypeScript: How to delegate interface methods

I have an interface like this coming from an 3rd party lib: MyInterface{ foo(arg: string): Promise; foo(arg: string, ...params: any[]): Promise; foo(arg: string): Promise; foo(arg: string, ...params: any[]):…
Chriss
  • 5,157
  • 7
  • 41
  • 75
0
votes
0 answers

Is there a way to override a global variable in a closure's scope?

I have an API has a signature like on(eventName, Handler) Where API users use it like on('myEvent', (safeAccessObject) => { safeAccessObject.doSomething(); }); Sometimes though, users refer to a global that I'd prefer them not to: // assume…
OpherV
  • 6,787
  • 6
  • 36
  • 55
0
votes
1 answer

Spring and Hibernate mash-up, object that is proxy of an @Entity with an extra @Service added on

I think this may be a case where I know the answer but just don't like it. My starting point was an earlier question, Hibernate @Entity conflict with Spring @Autowired for non-column object. I have an @Entity which is "naturally" linked in a…
0
votes
1 answer

Why Proxy pattern is categorized in Structural pattern?

According to Structural Patterns, they focus on how classes and objects are composed to form larger structures. Adapter and Decorator fit this definition. But for proxy it's just an interaction between the subject and the real object, it's not…
Gautam Naik
  • 109
  • 2
  • 11
0
votes
0 answers

Do we have a generic proxy template class (with customization points) somewhere?

With a healthy dose of fear for reinventing the wheel - im looking for a generic template for a proxy like object that will help me customize the constructor - a very basic and unfinished sketch look like this: template struct proxy { …
darune
  • 10,480
  • 2
  • 24
  • 62
0
votes
1 answer

Javascript observer or proxy without all changes going through proxy

I'm writing a subclass of arrays in Javascript to have better support for matrix operations (I know others exist, this is partially for me to re-teach myself linear algebra), and what I want is to have some properties that are reset whenever any…
lmhamilt
  • 127
  • 2
  • 8
0
votes
0 answers

Instance proxy with monkey-patched method

I need a way to create a "proxy" to an instance with monkey-patched methods/fields. I don't want to use a context manager and/or directly modify the instance. I cannot use inheritance - I'm given an instance, that's it. Do you know of any package…
damisan
  • 1,037
  • 6
  • 17
1 2 3
8 9