Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating method dependency in java

I have two methods names as sendSData() and sendCData() in MyClass.

class MyClass
{

       public void sendSData()
        {
          // Receiving Response from database
        }

        public void sendCData()
        {
         // send C Data
        }

}

I'm calling these two method from main method

public static void main(String ... args)
{
    MyClass obj=new MyClass();
    obj.sendSData();
    obj.sendCData();
}

It is possible for me to send sendCData request after if and only if I got success response from sendSData() method.

How can I achieve this in java?

sendData() publishing data to server . if I get success response from server then it will be possible for me to send sendCData(). I'm usung pub/sub model. I'm not calling any web service or REST service. for receiving respose I have separate subscriber

like image 313
John Tommy Avatar asked Aug 31 '26 09:08

John Tommy


1 Answers

public boolean sendSData() {
    // handle whether or not the function returns true or false
    return true;
}

public static void main(String ... args) {
    MyClass obj=new MyClass();

    if (obj.sendSData()) {
        obj.sendCData();
    } else {
        // obj.sendSData() did not successfully respond
    }
}

With the above code obj.sendCData() will only run if sendSData() returns true (successfully responded).

like image 68
Nicolas Avatar answered Sep 02 '26 22:09

Nicolas