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

50%
+0 −0
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?

General information As indicated in the comments you are looking for something similar to the Facade pattern. It is still not clear what you are trying to achieve, but the X class seems that it wi...

posted 3y ago by Alexei‭

Answer
#1: Initial revision by user avatar Alexei‭ · 2021-05-07T14:57:22Z (over 3 years ago)
### General information

As indicated in the comments you are looking for something similar to the [Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern). It is still not clear what you are trying to achieve, but the X class seems that it [will tackle way too many things](https://en.wikipedia.org/wiki/God_object). 

In order to avoid adding a lot of logic in one class (even if it only acts as a facade or proxy for other functionality), you should consider splitting the application logic in a way that makes it more maintainable. An example of architecture that does the job very nicely is the clean architecture ([implementation example](https://github.com/jasontaylordev/CleanArchitecture)).

The idea is to split the logic into use cases so that there is a very good match between the business requirement (use case) and how the logic is implemented. The aforementioned example solution relies on a [CQRS implementation](https://en.wikipedia.org/wiki/Command%E2%80%93query_separation) that does this separation.

### Your case (as I can guess from the provided code)

Each use case would be mapped to a class that injects only the dependencies it needs. Examples:

- run automatic tests in a test environment relies on getting server data, getting credentials for that server and a test runner
- running some tests in prod relies on getting production server data, getting credentials and using a smoke tests runner 

Of course, if a scenario applies to all environments, it can receive an environment identifier and act both on test and production.

I know that this is not a direct answer to your question, but I think that such an implementation (or similar) would ensure a good decoupling (e.g. some testing environments functionality should never be run in prod) and increased maintenance (e.g. making changes to test related flows is less likely to mess up with production only flows).