Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I would like to use Callbacks in my StateMachine to fetch values from Callback class, that is set in the native Android code.

Is this a right approach to create one? Do you see any issues with the code?

public class PrintCallBack {
    private static String bluetoothDevices = "";
    private static String errorMsg = "";
    private static int result = 0;

    public static String getBluetoothDevices() {
        return bluetoothDevices;
    }

    public static void setBluetoothDevices(String bluetoothDevices) {
        PrintCallBack.bluetoothDevices = bluetoothDevices;
    }

    public static String getErrorMsg() {
        return errorMsg;
    }

    public static void setErrorMsg(String errorMsg) {
        PrintCallBack.errorMsg = errorMsg;
    }

    public static int getResult() {
        return result;
    }

    public static void setResult(int result) {
        PrintCallBack.result = result;
    }

    public static void initialize(){
        bluetoothDevices = "";
        errorMsg = "";
        result = 0;
    }
}
share|improve this question

closed as unclear what you're asking by rolfl, Glenn Rogers, Nikita Brizhak, Yuushi, syb0rg Jan 28 '14 at 13:42

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

    
What Callback class? How would this code be used exactly? –  Simon André Forsberg Jan 24 '14 at 13:22
1  
Without additional details it is not practical to review this code. –  rolfl Jan 28 '14 at 4:32

1 Answer 1

Some random thoughts:

  1. Callback is one word, I'd name the class PrintCallback (lowercase b).

  2. If these methods are called from separate threads you need proper synchronization.

  3. Is it have to be static? Static variables, singleton classes usually makes testing harder because their global state - they have to be reset before every test case. Forgetting that could lead to fragile tests and tests may fail depending on their order.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.