-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
published: true | ||
title: "Observer pattern - Design Patterns" | ||
excerpt: "The observer pattern is a behavioural pattern." | ||
category: "Programming" | ||
tags: ["oop", "programming", "design-patterns"] | ||
date: "2024-10-23T07:35:00.322Z" | ||
author: | ||
name: "M Ferreira" | ||
picture: "https://res.cloudinary.com/mannuel/image/upload/f_auto/v1604067445/images/mee.jpg" | ||
ogImage: | ||
url: "https://res.cloudinary.com/mannuel/image/upload/v1729574243/mfcom/uvqa1m0nuuoahqii7mof.png" | ||
coverImage: "https://res.cloudinary.com/mannuel/image/upload/v1729574243/mfcom/uvqa1m0nuuoahqii7mof.png" | ||
--- | ||
|
||
## Pattern type | ||
|
||
This is a behavioural pattern that allows a one-to-many relationship between objects so that when the state of one object changes all its children objects are notified and updated automatically. | ||
|
||
## Intent | ||
|
||
The pattern intent is to make it easier to maintain consistency between related objects without making them tightly coupled. | ||
|
||
## Problem | ||
|
||
... | ||
|
||
## Pattern | ||
|
||
```mermaid | ||
classDiagram | ||
class Observer { | ||
+calculateTotal() | ||
+calulateShipping() | ||
} | ||
``` | ||
|
||
## Code example | ||
|
||
````python | ||
class Subject: | ||
def __init__(self): | ||
pass | ||
|
||
```python | ||
class Observer: | ||
def __init__(self): | ||
pass | ||
```` | ||
|
||
```python | ||
... | ||
``` | ||
|
||
prints out: | ||
|
||
```text | ||
... | ||
``` |