Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Virtual Proxy pattern #2940

Closed
iluwatar opened this issue May 6, 2024 · 1 comment
Closed

Implement Virtual Proxy pattern #2940

iluwatar opened this issue May 6, 2024 · 1 comment

Comments

@iluwatar
Copy link
Owner

iluwatar commented May 6, 2024

The Virtual Proxy design pattern is used to delay the creation and loading of expensive objects until their actual use, thereby reducing resource consumption. Here are the main points to consider when implementing this pattern:

  1. Proxy Class:

    • Implement a proxy class that implements the same interface or inherits from the same base class as the actual expensive object. This class acts as a stand-in for the real object.
    • The proxy class holds a reference to the real object, but initializes it only when necessary.
  2. Real Subject (Expensive Object):

    • Implement the actual, resource-intensive object, known as the real subject or real object.
    • Ensure that the interface provided by the real object matches that of the proxy.
  3. Deferred Initialization:

    • In the proxy class, encapsulate the creation logic of the real object.
    • Initialize the real object lazily, meaning that it is created only when one of its methods is accessed.
  4. Transparent Usage:

    • The proxy should appear to be the real object to clients.
    • The client should not notice whether they are accessing the proxy or the real object. All interactions should be routed seamlessly to the real object through the proxy.
  5. Efficiency Considerations:

    • Implement caching mechanisms or logic to prevent redundant initialization.
    • Make sure that the proxy introduces minimal overhead and improves performance in cases where the real object is not always required.

By encapsulating resource management in this way, the Virtual Proxy pattern makes expensive operations more efficient and ensures that unnecessary resource usage is avoided.

Acceptance Criteria:

  • Implementation: The Virtual Proxy pattern is implemented following the project's contribution guidelines and includes an interface and a proxy class to encapsulate the actual object.

  • Documentation: The implementation is documented with clear examples, diagrams, and explanations in the README.md file.

  • Tests: Comprehensive unit tests validate the behavior of the proxy in controlling object creation and access.

@Adelechka
Copy link
Contributor

Hi, can you assign it to me?

Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 12, 2024
Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 12, 2024
Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 12, 2024
Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 12, 2024
Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 12, 2024
Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 14, 2024
Adelechka added a commit to Adelechka/java-design-patterns that referenced this issue May 14, 2024
iluwatar pushed a commit that referenced this issue May 15, 2024
* feature: Implement Virtual Proxy pattern #2940

* feature: Implement Virtual Proxy pattern #2940

* feature: Implement Virtual Proxy pattern #2940

* feature: Implement Virtual Proxy pattern #2940

* feature: Implement Virtual Proxy pattern #2940

* feature: Implement Virtual Proxy pattern, tests added

* feature: Implement Virtual Proxy pattern, tests added

* feature: Implement Virtual Proxy pattern, tests added

* feature: Implement Virtual Proxy pattern, tests added

* feature: Implement Virtual Proxy pattern, tests added

* feature: Implement Virtual Proxy pattern #2940

* feature: Implement Virtual Proxy pattern #2940

* refactoring: proxy/pom.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants