0% found this document useful (0 votes)
2 views1 page

Behavioral Patterns Cheatsheet

This cheat sheet outlines key behavioral design patterns including Template Method, Strategy, Iterator, Mediator, and Observer. Each pattern is briefly described with its purpose and a code snippet example. The document serves as a quick reference for understanding these design patterns and their implementations.

Uploaded by

23-101028
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Behavioral Patterns Cheatsheet

This cheat sheet outlines key behavioral design patterns including Template Method, Strategy, Iterator, Mediator, and Observer. Each pattern is briefly described with its purpose and a code snippet example. The document serves as a quick reference for understanding these design patterns and their implementations.

Uploaded by

23-101028
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Behavioral Design Patterns Cheat Sheet

Template Method

Defines a fixed algorithm structure with customizable steps using inheritance.


abstract class GameAI {
void turn(){ step1(); step2(); }
abstract void step2();
}

Strategy

Encapsulates interchangeable algorithms and allows switching at runtime.

interface Strategy { void execute(); }


class Context { Strategy s; }

Iterator

Provides sequential access to elements without exposing internal structure.

interface Iterator { boolean hasNext(); Object next(); }

Mediator

Centralizes communication between objects.


interface Mediator { void notify(); }
class Colleague { Mediator m; }

Observer

Notifies multiple objects automatically when state changes.

interface Observer { void update(); }


class Subject { notifyObservers(); }

You might also like