Modeling Interactions

Dispatcher Interaction

A client of type Client sends a dispatcher of type Dispatcher one of two messages: serviceA or serviceB. Each takes a parameter cmmd of type String, a parameter c of type Client, and returns a result of type String. There are two servers of type Server1 and Server2. Server1 implements serviceA and Server2 implements serviceB. Both implement a private method called execute that takes an input of type String—the command—and returns a result of type String—the result. When the client calls the dispatcher's serviceA with arguments this and op1, the dispatcher asynchronously calls serviceA of server1, which executes the command, then returns the result directly to the client.

Pipeline Interaction

A client of type Client sends a message of type string to a translator of type Translator1. The translator translates the message, then sends the translated message to a second translator of type Translator2.  The message is further translated then sent to a consumer of type Consumer. The consumer consumes the message.

Supply Chain

A client of type Client sends a message of type string to a processor of type Processor1. The processor pre-processes the message, then sends the pre-processed message to a second processor of type Processor2.  Processor2 pre-processes the message, then sends the pre-processed message to a server of type Server. The server processes the message, then returns the result back to processor2 where it is post-processed. The post-processed result is returned to processor1 where more post-processing occurs. The result is returned to the client.

Helper Interaction

A client of type Client sends a factory of type Factory a request of type String. The factory sends a request to factory1 of type Factory1. Factory1 assembles a component of type Component1 and returns it to factory. The factory sends a request to factory2 of type Factory2. Factory2 assembles a component of type Component2 and returns it to factory. Factory assembles these components and returns the result to the client.

Reverse Engineering

Draw a sequence diagram that shows what happens when a user actor calls the indicated target method.

class Client {
   Server myServer;
   void process(String result) { ... }
   //target method:
   String sendRequest(String request) {
      boolean connected = myServer.connect(this);
      if (connected) {
         String result = myServer.post(request);
         process(result);
         return result;
      } else {
         return "refused";
      }
   }
}

 

class Cart {
   Collection<Item> contents;
   // target method:
   double getTotal() {
      double total = 0;
      for(Item item: contents) {
         total += item.getPrice();
      }
      return total;
   }
}

Recursion

Draw a sequence diagram that shows what happens when a user actor calls the indicated target method with input 4.

class Calculator {
   public int fact(int n) {
      if (n == 0) return 1;
      return n * fact(n – 1);
   }
}