Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:25:45+00:00 2026-06-01T22:25:45+00:00

For people who are familiar with bridge pattern, we know it uses composition to

  • 0

For people who are familiar with bridge pattern, we know it uses composition to include the concrete implementer as part of the refined abstraction. so basically we are expected to use the Abstraction as a client of this pattern.
enter image description here
/–Implementer–/
Interface Implementer extends AutoClosable {
public void open();
public void close();
}

/**--Concrete ImplementerA--**/
ImplementerA implements Implementer {
    public void open(){....};
    public void close(){......};
}
/**--Abstration--**/
public abstract class Abstraction {
    protected Implementer implementer;
    public methodAIwant2use();
    public methodBIwant2use();
}
/**--Refined Abstration--**/
public class RefinedAbstraction {
    public RefinedAbstraction(String Implementer) {
        this.implementer=Implementer;
    }
    public methodAIwant2use();
    public methodBIwant2use();
}

As the code above shown, I’ve hit an issue where my implementer happens to be an AutoClosable. In my case, I will directly use Abstraction at the client side and use a string as the constructor parameter to determine what concrete implementer I will use. But this kinda leaves me in a situation where I can’t use try-with-resources(Abstraction ab = new RefinedAbstraction(“implementorA”)), because Complier would complain that my abstraction is not a AutoCloseable. It doesn’t make sense to put concreteImplementor instance in the try-with-resouces block, because it’s the methods in Abstraction Interface actually wanted here.

The only way to get around this I can think of is that, I can use try/catch with finally block to explicitly close out my Abstraction.implementer instead of trying to use try-with-resources. But doing this means I have to increase the visibility of the implementer from protected to public which is not nice.

Any thoughts? or better approach for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:25:48+00:00Added an answer on June 1, 2026 at 10:25 pm

    You could make Abstraction itself an AutoCloseable and leave close() empty. A subclass that composes autocloseables would then override close to delegate the call to the composed object. Your client can then treat all Abstractions as autocloseable and interact with them consistently by using try-with-resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys! I've noticed that here are a lot of people who are familiar with
I know of some people who use git pull --rebase by default and others
This question is for the people who know both Haskell (or any other functional
I'm writing a little library that should be used by people who don't know
Explanation for people who don't know: this syntax means to Firefox : use the
It may sound very silly to people who know this but I am quite
As most people who work with Sql Server know, you can declare a temporary
This can be so easy to a people who know. I am almost finishing
Edit Since there were many downvotes and people who didn't understand what I'm asking
I am on a team of three people who are developing a Silverlight application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.