---
title: 10分でわかる_Observer &amp; Pub_Sub
tags: 
author: [Yuki Watanabe](https://www.docswell.com/user/YukiWatanabe824)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/3EKD3LXRJD.jpg?width=480
description: 社内勉強会で使用したスライド ジュニアレベルの輪読会でObserverパターンやPub/Subを解説しました。
published: August 02, 24
canonical: https://www.docswell.com/s/YukiWatanabe824/ZR23V9-2024-08-02-230548
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/3EKD3LXRJD.jpg)

10分でわかる
Observer &amp; Pub/Sub
渡邊有喜


# Page. 2

![Page Image](https://bcdn.docswell.com/page/L73RG35GJ5.jpg)

目的
Observerパターン学ぶ
Pub/Sub学ぶ


# Page. 3

![Page Image](https://bcdn.docswell.com/page/87DY14DN7G.jpg)

Observerとは
「一対多」の依存関係を定義したもの


# Page. 4

![Page Image](https://bcdn.docswell.com/page/VJP6QMXNE8.jpg)

Pub/Subとは
オブザーバーパターンを拡張したもの
「多対多」の依存関係を定義


# Page. 5

![Page Image](https://bcdn.docswell.com/page/2EV359LY7Q.jpg)

Observerとは
引用:オブジェクト指向における再利用のためのデザインパターン』


# Page. 6

![Page Image](https://bcdn.docswell.com/page/57G36ZXWJL.jpg)

いつ使うのか
一つのオブジェクトの変更から無数のオ
ブジェクトに処理を派生させたいとき


# Page. 7

![Page Image](https://bcdn.docswell.com/page/4EQ54L8QJP.jpg)

Observerは何が嬉しい
- オブジェクト間の矛盾が生まれづらい
- オブジェクト間で実装知らなくてOK
- ブロードキャスト通信のサポート


# Page. 8

![Page Image](https://bcdn.docswell.com/page/KJ49QD2Y71.jpg)

Observerとは
引用:Wikipedia


# Page. 9

![Page Image](https://bcdn.docswell.com/page/LE1KPZMNJG.jpg)

Observerとは
引用:オブジェクト指向における再利用のためのデザインパターン』


# Page. 10

![Page Image](https://bcdn.docswell.com/page/GEWD29DMJ2.jpg)

つよい人は考えた…
Subjectも複数使えたら便利じゃね
↓
Pub/Sub誕生
※想像です


# Page. 11

![Page Image](https://bcdn.docswell.com/page/47ZGD9GME3.jpg)

Pub/Subとは
オブザーバーパターンを拡張したもの
「多対多」の依存関係を定義


# Page. 12

![Page Image](https://bcdn.docswell.com/page/YJ6Y1KY57V.jpg)

Pub/Subとは
引用:https://laboratory.kiyono-co.jp/69/gcp/


# Page. 13

![Page Image](https://bcdn.docswell.com/page/GJ5G4PGGJ4.jpg)

Pub/SubとObserverの違い
- 「ブローカー」(中間テーブル)の存在
- Pub/Subはブローカーによる非同期処理


