---
title: "Forking, joining and branching in modeling"
subject: "Object Oriented Analysis and Design"
chapter: 2
key: "semester_6/object_oriented_analysis_and_design:forking-joining-branching-activity"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/forking-joining-branching-activity
site: BCT Engineering
---

# Forking, joining and branching in modeling

Object Oriented Analysis and Design · Chapter 2: Object Oriented Analysis

- Asked in: 2070 Bhadra, 4+4 marks
- Video: [Activity Diagram - Step by Step Guide with Example](https://www.youtube.com/watch?v=knM8BGY9yVI) — Master2Teach
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/forking-joining-branching-activity
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-2

## Question

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.

## 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.

## Answer

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.
```text
        [ 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).

```text
        ( 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.
```java
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(); }
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. At a branch (decision) diamond:
   A. It waits for all incoming flows
   B. Exactly one guarded outgoing flow is taken
   C. No guards are used
   D. All outgoing flows run in parallel
   Answer: B. Branches use Boolean guards and choose one path. (Key point: Branching)

2. A fork maps to which code construct?
   A. if / else
   B. A switch statement
   C. Starting threads or processes
   D. A try block
   Answer: C. Fork starts concurrent flows; join maps to thread.join() or a barrier. (Key point: Fork mapping)

3. A join proceeds when:
   A. A guard is false
   B. All incoming flows have arrived
   C. Any one flow arrives
   D. The first thread starts
   Answer: B. Join synchronises concurrent flows. (Key point: Join)

4. Why can an activity diagram be converted almost one to one into code?
   A. It uses only actors
   B. It lists database tables
   C. It stores class attributes
   D. It uses the same constructs as programs: decisions, loops, concurrency
   Answer: D. Branch, loop, fork and join correspond to program constructs. (Key point: Closest implementation model)

## Related in Object Oriented Analysis and Design

- [Object oriented system and core concepts](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aoo-system-concepts-explained) — Object Oriented Analysis and Design, chapter 1
- [Algorithmic vs object-oriented decomposition](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aalgorithmic-vs-oo-decomposition) — Object Oriented Analysis and Design, chapter 1
- [Structural model vs implementation model](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Astructural-vs-implementation-model) — Object Oriented Analysis and Design, chapter 1
- [Conceptual, specification, implementation model classification](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Ahospital-conceptual-specification-implementation) — Object Oriented Analysis and Design, chapter 2
- [Behavior modeling and four diagrams](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Abehavior-modeling-four-diagrams) — Object Oriented Analysis and Design, chapter 2
- [Domain modeling; attributes and associations guidelines](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Adomain-modeling-attributes-associations) — Object Oriented Analysis and Design, chapter 2

## Related in other subjects

- [Compare procedural and object oriented programming](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprocedural-vs-oop-compare) — Object Oriented Programming, chapter 1
- [Features of microprocessor based instrumentation](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Ambi-features) — Instrumentation II, chapter 1, asked 4×
- [Document Object Model with HTML/JavaScript](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Adom-html-javascript) — Web Technology, chapter 4, asked 2×
- [Manipulators available in C++](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Amanipulators) — Object Oriented Programming, chapter 8, asked 2×
