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 940721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:00:05+00:00 2026-05-15T22:00:05+00:00

I am creating a client side swing app that will have data provided by/from

  • 0

I am creating a client side swing app that will have data provided by/from one of many data providers(brokers). The data providers however, have varying ways of perfoming same things e.g.

broker1’s login method

public boolean doLogin(String username, String password);

broker2’s login method

public int login(String username, String password,String sessionId);

For all providers the set of required actions is the same
e.g

login, getstatus, sendRequest, getData, logOff
(but they have different params and return types)

I took a look at the adapter pattern but am unfortunately not able to use it well as the required methods have different parameters.

Is the adapter pattern usable in this case? if so how?
If not what would be the best way of doing this?

Thanks.

  • 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-05-15T22:00:05+00:00Added an answer on May 15, 2026 at 10:00 pm

    Patterns are general guidelines (starting point) of best practices. Many developers “adapts” the patterns to their needs; the important thing is, then, if you must use a pattern, use it consistently throughout your whole application.

    Now, to answer your question; yes the adapter pattern can very well be used in your situation. A possible solution (in the like) could be:

    abstract class BrokerAbstract<T> {
       private int errCode;
       private String errMessage;
    
       abstract public boolean login(String user, String pass, Map<String,Object> options);
       abstract public int getStatus(Map<String,Object> options);
       abstract public boolean sendRequest(Map<String,Object> options);
       abstract public T getData(Map<String,Object> options);
       abstract public boolean logOff(Map<String,Object> options);
    
       protected void setError(int code, String message) {
          this.errCode = code;
          this.errMessage = message;
       }
    
       public int getErrorCode() { return this.errCode; }
       public String getErrorMessage() { return this.errMessage; }
    }
    

    Then

    class Broker1 extends BrokerAbstract<Object> {
       private OriginalBroker1 original;       
    
       public boolean login(String user, String pass, Map<String,Object> options) {
          return original.doLogin(user, pass);  // ignore options
       }
       public boolean login(String user, String pass) {
          return login(user, pass, null);  // third parameters will be ignored
       }
       public int getStatus(Map<String,Object> options) { /*...*/ return 0; }
       public boolean sendRequest(Map<String,Object> options) { /*...*/ return false; }
       public Object getData(Map<String,Object> options) { 
          return original.getData();  // OriginalBroker1.getData():Object
       }
       public boolean logOff(Map<String,Object> options) {
          return original.doLogout((boolean) options.get("clearSession"));
       }
       public boolean logoff() {
          HashMap<String,Object> options = new HashMap<String,Object>();
          options.put("clearSession", true);
          return logoff(options);   // proxy to original method
       }
    }
    

    Or

    class Broker2 extends BrokerAbstract<Integer> {
       private OriginalBroker2 original;       
    
       public boolean login(String user, String pass, Map<String,Object> options) {
          int code = original.doLogin(user, pass, (String) options.get("sessionId"));
          if (0 != code) {
              setError(code, "Custom error message"); // could use enum here for messages...
              return false;
          } else {
              return true;
          }
       }
       public boolean login(String user, String pass, String sessionId) {
          HashMap<String,Object> options = new HashMap<String,Object>();
          options.put("sessionId", sessionId);
          return login(user, pass, options);
       }
       public int getStatus(Map<String,Object> options) { /*...*/ return 0; }
       public boolean sendRequest(Map<String,Object> options) { /*...*/ return true; }
       public Integer getData(Map<String,Object> options) { 
          return original.getData(options.get("key"));  // OriginalBroker2.getData(key:String):int
       }
       public boolean logOff(Map<String,Object> options) {
          return original.doLogout();
       }
       public boolean logoff() {
          return logoff(null);   // ignore third parameter
       }
    }
    

    Of course this is a very general approach. If you know that one method will be receiving strings for all parameters, you could also have a abstract signature like :

    abstract public boolean login(String...args);
    

    Then your concrete implementation would be :

    abstract class A {
       abstract public boolean login(String...args);    
    }
    class B extends A {
       public boolean login(String...args) { return this.login(args[0], args[1]); }
       public boolean login(String user, String pass) { return original.login(user,pass); }
    }
    
    class C {
       public void login() {
          B b = new B();
          b.login("foo", "secret");
          // or
          b.login(new String[] {"foo", "secret"});
          // or !
          b.login("foo", "secret", "sessionId");  // will ignore third, but otherwise would still work...
       }
    }
    

    etc.

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

Sidebar

Ask A Question

Stats

  • Questions 537k
  • Answers 537k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's because a Perl module has to return "true" in… May 17, 2026 at 1:38 am
  • Editorial Team
    Editorial Team added an answer There is an "include everything and the kitchen sink" maven… May 17, 2026 at 1:38 am
  • Editorial Team
    Editorial Team added an answer You have to enclose your pattern with double quote to… May 17, 2026 at 1:38 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am creating a client side application which needs to create a log of
I need to call ASP.Net server side code from the client. Because I'm in
I getting any error on a I'm creating in my client side code. The
Im creating a usercontrol which is controled client side, it has an javascript-file attatched
I'm creating an EnityList to do some client side testing with my ViewModel. Something
I'm creating registration page and I've done basic client side (JS) form validation. Now
I'm creating an out of browser silverlight app and would like to have a
I'm doing an ajax work where web service will return data and on client
I'm creating the server side implementation of an AJAX based web application, where the
I'm creating a web-service client. I used a WSDL file to generate the client

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.