<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Behavioral on Java &amp; Software Architecture Knowledge Hub</title><link>https://samirsahoo.github.io/design-patterns-hub/tags/behavioral/</link><description>Recent content in Behavioral on Java &amp; Software Architecture Knowledge Hub</description><generator>Hugo</generator><language>en-US</language><copyright>© 2026 Samir Kumar Sahoo (https://github.com/samirsahoo). All rights reserved.</copyright><atom:link href="https://samirsahoo.github.io/design-patterns-hub/tags/behavioral/index.xml" rel="self" type="application/rss+xml"/><item><title>Strategy vs State vs Template Method</title><link>https://samirsahoo.github.io/design-patterns-hub/comparisons/strategy-state-template-method/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/comparisons/strategy-state-template-method/</guid><description>&lt;h2 id="the-short-answer"&gt;The short answer&lt;a class="heading-anchor" href="#the-short-answer" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;div class="table-wrap" tabindex="0" role="region" aria-label="Table"&gt;&#10;&lt;table&gt;&#10; &lt;thead&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;Pattern&lt;/th&gt;&#10; &lt;th&gt;What varies&lt;/th&gt;&#10; &lt;th&gt;How&lt;/th&gt;&#10; &lt;th&gt;Who chooses&lt;/th&gt;&#10; &lt;/tr&gt;&#10; &lt;/thead&gt;&#10; &lt;tbody&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;strong&gt;&lt;a href="https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/strategy/"&gt;Strategy&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;&#10; &lt;td&gt;The whole algorithm&lt;/td&gt;&#10; &lt;td&gt;Composition: the context holds an interchangeable object&lt;/td&gt;&#10; &lt;td&gt;The &lt;strong&gt;client&lt;/strong&gt;, usually once&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;strong&gt;&lt;a href="https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/state/"&gt;State&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;&#10; &lt;td&gt;Behaviour per lifecycle state&lt;/td&gt;&#10; &lt;td&gt;Composition: the context holds the current state object&lt;/td&gt;&#10; &lt;td&gt;The &lt;strong&gt;states themselves&lt;/strong&gt;, on each transition&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;strong&gt;&lt;a href="https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/template-method/"&gt;Template Method&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;&#10; &lt;td&gt;Some steps of a fixed algorithm&lt;/td&gt;&#10; &lt;td&gt;Inheritance: subclasses override steps&lt;/td&gt;&#10; &lt;td&gt;The &lt;strong&gt;subclass&lt;/strong&gt;, at compile time&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;The deciding questions:&lt;/p&gt;</description></item><item><title>All 23 GoF Patterns: Overview and Classification</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/gof-overview/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/gof-overview/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Gang of Four (GoF) catalogue&lt;/strong&gt; is the set of 23 object-oriented design patterns published in &lt;em&gt;Design Patterns: Elements of Reusable Object-Oriented Software&lt;/em&gt; (1994). The book sorts them along two axes:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Purpose&lt;/strong&gt; — what the pattern does: &lt;em&gt;creational&lt;/em&gt;, &lt;em&gt;structural&lt;/em&gt; or &lt;em&gt;behavioral&lt;/em&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Scope&lt;/strong&gt; — whether the relationships are fixed at compile time through inheritance (&lt;em&gt;class&lt;/em&gt; scope) or set up at runtime through composition (&lt;em&gt;object&lt;/em&gt; scope).&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;This page is the map. Each pattern gets its own article; patterns not yet written are listed as plain text so that no page pretends to be finished.&lt;/p&gt;</description></item><item><title>Observer vs Mediator vs Event Bus</title><link>https://samirsahoo.github.io/design-patterns-hub/comparisons/observer-mediator-event-bus/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/comparisons/observer-mediator-event-bus/</guid><description>&lt;h2 id="the-short-answer"&gt;The short answer&lt;a class="heading-anchor" href="#the-short-answer" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;div class="table-wrap" tabindex="0" role="region" aria-label="Table"&gt;&#10;&lt;table&gt;&#10; &lt;thead&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;&lt;/th&gt;&#10; &lt;th&gt;&lt;a href="https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/observer/"&gt;Observer&lt;/a&gt;&lt;/th&gt;&#10; &lt;th&gt;&lt;a href="https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/mediator/"&gt;Mediator&lt;/a&gt;&lt;/th&gt;&#10; &lt;th&gt;Event bus (publish/subscribe)&lt;/th&gt;&#10; &lt;/tr&gt;&#10; &lt;/thead&gt;&#10; &lt;tbody&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Who knows whom&lt;/td&gt;&#10; &lt;td&gt;Subject knows its observers (through an interface)&lt;/td&gt;&#10; &lt;td&gt;Colleagues know the mediator; mediator knows colleagues&lt;/td&gt;&#10; &lt;td&gt;Publishers and subscribers know only the bus and event types&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Where the logic is&lt;/td&gt;&#10; &lt;td&gt;Each observer decides how to react&lt;/td&gt;&#10; &lt;td&gt;&lt;strong&gt;Centralised&lt;/strong&gt; in the mediator&lt;/td&gt;&#10; &lt;td&gt;Each subscriber decides; nobody coordinates&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Direction&lt;/td&gt;&#10; &lt;td&gt;One-to-many broadcast&lt;/td&gt;&#10; &lt;td&gt;Many-to-one-to-many, two-way&lt;/td&gt;&#10; &lt;td&gt;Many-to-many broadcast&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Control flow&lt;/td&gt;&#10; &lt;td&gt;Easy to find: look at the subject&amp;rsquo;s observers&lt;/td&gt;&#10; &lt;td&gt;Easy to find: read the mediator&lt;/td&gt;&#10; &lt;td&gt;Hard to find: search for subscribers of an event type&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Typical scope&lt;/td&gt;&#10; &lt;td&gt;One object and its dependents&lt;/td&gt;&#10; &lt;td&gt;One dialog, workflow or interaction&lt;/td&gt;&#10; &lt;td&gt;A whole application, or many services via a broker&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;The deciding questions:&lt;/p&gt;</description></item><item><title>Chain of Responsibility Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/chain-of-responsibility/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/chain-of-responsibility/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Chain of Responsibility&lt;/strong&gt; pattern passes a request along a &lt;strong&gt;chain of handler objects&lt;/strong&gt;. Each handler either handles the request or passes it to the next one. The sender does not know which handler will deal with it.&lt;/p&gt;</description></item><item><title>Command Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/command/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/command/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Command&lt;/strong&gt; pattern wraps a request — &amp;ldquo;insert this text at position 5&amp;rdquo; — in an &lt;strong&gt;object&lt;/strong&gt;. Because the request is now a value, it can be stored in a history, undone, redone, queued for later, sent to another thread or logged and replayed.&lt;/p&gt;</description></item><item><title>Interpreter Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/interpreter/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/interpreter/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Interpreter&lt;/strong&gt; pattern defines a class for each rule of a small language&amp;rsquo;s &lt;strong&gt;grammar&lt;/strong&gt;. A sentence in the language is parsed into a tree of these objects (an &lt;strong&gt;abstract syntax tree&lt;/strong&gt;, AST), and calling &lt;code&gt;interpret(context)&lt;/code&gt; on the root evaluates it recursively.&lt;/p&gt;</description></item><item><title>Iterator Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/iterator/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/iterator/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Iterator&lt;/strong&gt; pattern gives a way to visit the elements of a collection &lt;strong&gt;one at a time, without exposing how the collection is stored&lt;/strong&gt;: an array, a linked list, a tree, a database cursor or pages from a remote API.&lt;/p&gt;</description></item><item><title>Mediator Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/mediator/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/mediator/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Mediator&lt;/strong&gt; pattern puts the rules for how a group of objects interact into &lt;strong&gt;one object&lt;/strong&gt;, the mediator. The objects (colleagues) report events to the mediator instead of calling each other; the mediator decides what happens next.&lt;/p&gt;</description></item><item><title>Memento Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/memento/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/memento/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Memento&lt;/strong&gt; pattern lets an object save a &lt;strong&gt;snapshot&lt;/strong&gt; of its internal state and later restore it, while keeping that state &lt;strong&gt;private&lt;/strong&gt;: other objects can store snapshots but cannot read or change what is inside them.&lt;/p&gt;</description></item><item><title>Observer Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/observer/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/observer/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Observer&lt;/strong&gt; pattern lets an object (the &lt;strong&gt;subject&lt;/strong&gt;) keep a list of interested objects (&lt;strong&gt;observers&lt;/strong&gt;) and notify all of them automatically when something happens. The subject knows only that observers implement a small interface; it does not know what they do.&lt;/p&gt;</description></item><item><title>State Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/state/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/state/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;State&lt;/strong&gt; pattern moves state-specific behaviour into separate &lt;strong&gt;state objects&lt;/strong&gt;. The main object (the &lt;strong&gt;context&lt;/strong&gt;) delegates each request to its current state object, and the state object decides what to do and which state comes next. To the outside, the object appears to change its class.&lt;/p&gt;</description></item><item><title>Strategy Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/strategy/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/strategy/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Strategy&lt;/strong&gt; pattern defines a family of algorithms, puts each one in its own class behind a common interface, and lets the client choose which one to use. The code that &lt;em&gt;uses&lt;/em&gt; the algorithm does not change when you add a new one.&lt;/p&gt;</description></item><item><title>Template Method Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/template-method/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/template-method/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Template Method&lt;/strong&gt; pattern puts the &lt;strong&gt;fixed outline of an algorithm&lt;/strong&gt; in a base-class method (the template method) and leaves certain &lt;strong&gt;steps&lt;/strong&gt; for subclasses to implement. Subclasses change the steps, never the order.&lt;/p&gt;&#10;&lt;p&gt;GoF intent: &lt;em&gt;&amp;ldquo;Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm&amp;rsquo;s structure.&amp;rdquo;&lt;/em&gt;&lt;/p&gt;</description></item><item><title>Visitor Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/visitor/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/behavioral/visitor/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Visitor&lt;/strong&gt; pattern moves an operation out of the classes it works on and into a separate &lt;strong&gt;visitor&lt;/strong&gt; object. Each class in the hierarchy has one generic &lt;code&gt;accept(visitor)&lt;/code&gt; method; adding a new operation means writing a new visitor, not editing every class.&lt;/p&gt;</description></item></channel></rss>