Skip to main content

Forking, joining and branching in modeling

Short answer

Branching (decision/merge) maps to if/else with guarded flows. Forking splits into concurrent flows (thread start). Joining synchronizes parallel flows (thread join). These primitives directly correspond to programming constructs, enabling near one-to-one translation from activity diagrams to code.

Explain the forking, joining, and branching features available in object-oriented based modeling. How does these primitive provide the closest implementation model? Relate with any arbitrary sample.

In the UML activity diagram, a workflow is made of activities connected by transitions. The three primitives below control the flow.

Branching (decision and merge)

A branch is a diamond with one incoming flow and two or more outgoing flows, each guarded by a Boolean condition in square brackets. Exactly one outgoing flow is taken. A merge diamond brings alternative flows back together.

        [ Check Stock ]
              |
           < in stock? >
          [yes] /   \ [no]
     [Pack item]   [Order from supplier]
          \         /
           (merge)

Forking

A fork is a thick bar with one incoming flow and several outgoing flows. All outgoing flows are performed concurrently (in parallel).

Joining

A join is a thick bar that has several incoming flows and one outgoing flow. The outgoing flow proceeds only when all incoming flows have arrived (synchronisation).

        ( Order accepted )
               |
       ===================   fork
         |            |
  [Pack goods]   [Prepare invoice]
         |            |
       ===================   join
               |
         [ Dispatch ]

How they give the closest implementation model

  • Branch maps directly to if / else and switch statements.
  • Fork maps to starting threads or processes (new Thread(...).start()), and join to thread.join() or a barrier.
  • A loop is a branch whose "no" flow returns to an earlier activity (while).
  • Because activity diagrams use the same constructs as programs, an activity diagram can be converted almost one to one into code.

Sample (online order): Accept order -> branch on payment valid? -> if no, send rejection; if yes, fork into "pack goods" and "prepare invoice", join, then dispatch.

if (paymentValid) {
    Thread t1 = new Thread(() -> pack());
    Thread t2 = new Thread(() -> invoice());
    t1.start(); t2.start();      // fork
    t1.join();  t2.join();       // join
    dispatch();
} else { reject(); }

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Analysis and Design chapter 2 questions →