Question

Well this may be a simple question but, this got me worried a lot. we were given a java code and were asked to convert into sequence diagram. the java code goes like this.

   class onlinemealsellingsystem
     {
            public static void main(String[] args)
            {
              DinnerNowSystem dns =new DinnerNowSystem();
              Customer c = new Customer();
              Restaurent r = new Restaurent();
              Bank b = new Bank();

              c.addOrderItems();
              c.confirmOrder();
              dns.sendorder();
              c.payment();
              r.deliverfood();
           }
          }

the corresponding classes have corresponding functions defined. after the exam the solution i found is something like this.

diagram

In the exam I thought the online meal selling system will send message(addorderitems) to customer.

Where was my thought process going wrong? why should not it happen like that?

Please give me examples of conversion from java code to sequence diagram.

Was it helpful?

Solution

I would say that someone has understood UML upside down, and it isn't you: the UML specification (UML Superstructure Specification, v2.4.1 pag. 504) defines a CallEvent (i.e. arrow) as the reception by an object of a message invoking a call of an operation. For instance, see here.

My understanding is that the given diagram does not represent the given code.

  • In the diagram, it is the Customer who sends an add order item to the Dinner Now System (makes sense)
  • In the code, it is the onlinemealsellingsystem sends a addOrderItems to the Customer (doesn't make sense).

Leaving aside the parameters (since they are not specified in your examplethe source code corresponding to the diagram would be similar to:

    class Customer {

      public void iWannaEat() {

         DinnerNowSystem dns =new DinnerNowSystem();              
         Restaurant r = new Restaurant();
         Bank b = new Bank();

         while (...) dns.addOrderItem();
         dns.confirmOrder();
         dns.sendorder();
         dns.paymentDetail();
         Food f = r.receiveFood();
       }
      }

    class DinnerNowSystem() {
        Bank b;
        Restaurant r; 
        void addOrderItem();
        void confirmOrder() {
         r.sendOrder();
        }
        void paymentDetail() {
         if (b.processPayment())
            r.confirmOrder() 
            else halt and catch fire; 
        }
    }

Note also that, if the code and the UML diagram that you posted are corresponding each other, the code misses the loop that is present in the diagram. That is just weird.

Note also that it is the Customer who waits until the Restaurant delivers it the food.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top