How to reorganize a class containing many internal classes of the listener?

I am writing an Android application that receives location updates and sends requests to a web service. The application has several actions and uses the local service as a controller. The problem is that this “controller” service quickly turns into an anti-Blob / God pattern. I am trying to find a better way to refract code.

Almost all functions are asynchronous, as the http client must be run in a separate thread. Most methods call listeners to receive a response from the server. Location updates are also accepted through the listener. All of these listeners are currently implemented as inner classes in my local service. I now have about 10 inner classes inside my local service. I don’t see how I can move these listeners to separate classes, because they need access to the state stored in the Service. I tried to implement a singleton / observer hybrid class that processes all state, receiving updates from each of the listeners, and then passing them to any registered observers, but this is not a good solution, since it has all the problems,associated with global status and it is difficult to monitor the flow of programs from one place to another. After re-recording, refactoring and re-recording again, I am now completely confused and do not know what to do. Any tips?

+3
source share
1 answer

Two thoughts. 1) This pop-up code for processing a visible event is hidden in the MS Net IDE and, optionally, in the Mac IDE, by folding event handlers and providing an icon to expand the section of the event code. Therefore, I do not see the bloating of the event handling code, and this does not bother me. Out of sight, out of mind.

2) for Android 1.6+, you could reorganize the XML attributes

<Button android:text="@string/get_plain_text_button"
android:id="@+id/ButtonPlainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick= "plainTextOnClickHandler">

which corresponds to the method:

public voidplainTextOnClickHandler(View v){
    editTextPlainText.setText("Plain Text Button Clicked");
}

Jal

0
source

All Articles