Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

62%
+3 −1
Q&A Is this a known design pattern: a piece of code is responsible for acting as a central proxy for data distributed in various places?

I have several classes (C_1...C_n) and their instances (I_1....I_m). I have a "Registry" R of these. There are several pieces of data (d_1...d_k) spread across various instances. This much is set ...

1 answer  ·  posted 3y ago by peey‭  ·  last activity 3y ago by Alexei‭

Question design-patterns
#2: Post edited by user avatar peey‭ · 2021-05-05T14:07:32Z (over 3 years ago)
Clarify by adding an example
  • I have several classes (`C_1`...`C_n`) and their instances (`I_1`....`I_m`). I have a "Registry" `R` of these.
  • There are several pieces of data (`d_1`...`d_k`) spread across various instances. This much is set in stone, i.e. I consider the data being spread across the instances as appropriate design.
  • Now while writing the code in `C_i`, each class does know how to access the data that it's responsible for (among the `d_j`), but I wouldn't like it to have that knowledge for the data in other classes / instances.
  • I'm thinking of achieving this by declaring a singleton class `X` which has access to this registry, and it acts as a proxy between the actual location of the data (in `I_j`) and the name of the data `d_k`.
  • So using `X`, anywhere in my program I can write `X.get_d2()` and I'll get `d2`, without worrying about where it came from.
  • Is this a known design pattern? If not, then are there any obvious pitfalls with this design that some other patterns are known to mitigate?
  • I have several classes (`C_1`...`C_n`) and their instances (`I_1`....`I_m`). I have a "Registry" `R` of these.
  • There are several pieces of data (`d_1`...`d_k`) spread across various instances. This much is set in stone, i.e. I consider the data being spread across the instances as appropriate design.
  • ```
  • class Server { // C1
  • public String host; // d_i
  • public String port;
  • //....
  • }
  • class Administrator { // C2
  • public String username; // d_j
  • public String hashed_password;
  • public Server belongs_to;
  • //....
  • }
  • // ....
  • class SomethingElse { // Cn
  • // more of this later
  • }
  • class RegistryOfWellKnownInstances {
  • getServers(); // I_j
  • getAdministrators(); // I_k
  • // ...
  • }
  • ```
  • Now while writing the code in `C_i`, each class does know how to access the data that it's responsible for (among the `d_j`), but I wouldn't like it to have that knowledge for the data in other classes / instances.
  • ```
  • /**
  • * Let's say there's a concept of certain well-known instances with the Registry. There are servers "testing" and "prod" and we want access to the host name (d_i) and admin usernames (d_j) for them.
  • * This class doesn't have too much knowledge about the `Server` class or `Administrator` class. They are complex classes, and perhaps managed by another set of programers. It doesn't even care about how/where these instances are created and how it'll have access to those instances.
  • */
  • class SomethingElse {
  • // ...
  • }
  • ```
  • I'm thinking of achieving this by declaring a singleton class `X` which has access to this registry, and it acts as a proxy between the actual location of the data (in `I_j`) and the name of the data `d_k`.
  • ```
  • // I could directly encode logic for getting the data from the registry in the class "SomethingElse", but it's actually needed by others as well, so let's define something common
  • class X {
  • // NOTE: I'm aware that I can parametrize this with "prod" or "testing" but for sake of example let's say these are simple getters without a parameter.
  • // These methods would work by essentially getting instance from registry and just invoking appropriate getters / accessing appropriate fields
  • get_prod_hostname() // d1
  • get_testing_hostname() // d2
  • get_prod_admins() // d3
  • get_testing_admins() // d4
  • // ....
  • }
  • ```
  • So using `X`, anywhere in my program I can write `X.get_d2()` and I'll get `d2`, without worrying about where it came from.
  • Is this a known design pattern? If not, then are there any obvious pitfalls with this design that some other patterns are known to mitigate?
#1: Initial revision by user avatar peey‭ · 2021-05-05T11:46:59Z (over 3 years ago)
Is this a known design pattern: a piece of code is responsible for acting as a central proxy for data distributed in various places?
I have several classes (`C_1`...`C_n`) and their instances (`I_1`....`I_m`). I have a "Registry" `R` of these. 

There are several pieces of data (`d_1`...`d_k`) spread across various instances. This much is set in stone, i.e. I consider the data being spread across the instances as appropriate design.

Now while writing the code in `C_i`, each class does know how to access the data that it's responsible for (among the `d_j`), but I wouldn't like it to have that knowledge for the data in other classes / instances.

I'm thinking of achieving this by declaring a singleton class `X` which has access to this registry, and it acts as a proxy between the actual location of the data (in `I_j`) and the name of the data `d_k`. 

So using `X`, anywhere in my program I can write `X.get_d2()` and I'll get `d2`, without worrying about where it came from. 

Is this a known design pattern? If not, then are there any obvious pitfalls with this design that some other patterns are known to mitigate?