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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:08:35+00:00 2026-06-01T09:08:35+00:00

I’m currently developing the presentation layer of an android app. The api which I’m

  • 0

I’m currently developing the presentation layer of an android app.

The api which I’m using looks something like this:

public interface errorInterface{
    public void onError(String reason);
}

public interface if1 extends errorInterface{
    public void dataReceived1(Data data);
}
public interface if2 extends errorInterface{
    public void dataReceived2(Data data);
}   

public void fetchData1(if1 receiver) {}
public void fetchData2(if2 receiver) {}

That is; to fetch data you provide a receiver which will receieve the result of the operation sometime in the future.

This works very well when you need to call only one method at a time, but now I have reached the point when I need to call 10+ such methods in one go, and they need to execute one at a time.

How can I solve this in a flexible and elegant way?

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-01T09:08:37+00:00Added an answer on June 1, 2026 at 9:08 am

    Let me make sure I understand.. you have a series of interfaces if1, if2.. ifn and you want them all to be able to process the data received.

    First of all, it would be best if if1, if2, etc were all the same interface with your two basic methods: public void dataReceived(Data d) and public void onError(String reason). With that, you can simply pass a List or Collection of your receivers to fetchData and it can iterate over the collection and call dataReceived(d) on each one.

    If, for whatever reason, that’s unworkable, I would try an adapter to coax them into a similar interface for fetchData. For example:

    public interface DataReceiver extends ErrorInterface {
      public void dataReceived(Data d); 
      //or just scrap the ErrorInterface all together and make these into 1 interface
    }
    
    public class AbstractIFAdapter<T extends ErrorInterface> implements DataReceiver {
      private T target;
      public AbstractIFAdapter(T target) { this.target = target);
      public void onError(String reason) { target.onError(reason); }
      protected T getTarget() { return target; }
    }
    
    public class IF1Adapter extends AbstractIFAdapter<IF1> {
      public IF1Adapter(IF1 target) { super(target); }
      public dataReceived(Data d) { getTarget().dataReceived1(d); }
    }
    
    public class IF2Adapter extends AbstractIFAdapter<IF2> {
      public IF2Adapter(IF2 target) { super(target); }
      public dataReceived(Data d) { getTarget().dataReceived2(d); }
    }
    

    Now with that in place, we can do something like this:

    List<DataReceiver> dataReceivers = new ArrayList<DataReceiver>();
    dataReceivers.add(new IF1Adapter(someIf1Implementation));
    dataReceivers.add(new IF2Adapter(someIf2Implementation));
    fetchData(dataReceivers);
    
    public void fetchData(Collection<DataReceiver> receivers) {
    
      try {
        Data d = getSomeData();
        for (DataReceiver dr : receivers) {
          dr.dataReceived(d);
        }
      }
      catch (Exception e) {
        for (DataReceiver dr : receivers) {
          dr.onError(e.getMessage());
        } 
      }
    }
    

    There are other patterns that may be applicable depending on your exact needs such as visitors or perhaps a chain-of-responsibility type pattern where you chain your receivers together in a linked list type construct and each one calls the next in a recursive construct – this would be nice as fetchData wouldn’t need to know it is getting a collection, it just gets a reference to the top adapter in the chain. So, AbstractIFAdapter would have a reference to another AbstractIFAdapter, let’s call it next, and if the reference wasn’t null, it would call next.dataReceived(d) in its own dataReceived method. Similar idea as ServletFilters where each filter gets the ServletRequest and then calls chain.doFilter(request,response).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.