Notice: file_put_contents(): Write of 7268 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 8192 of 15460 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
Computer Science@CScience1 P.3125
CSCIENCE1 Telegram 3125
Паттерн Observer (Наблюдатель)

Observer позволяет объектам подписываться на события другого объекта. Когда событие происходит, все подписчики уведомляются автоматически.

Пример:
Представьте, что у вас есть социальная сеть, где пользователи могут подписываться на обновления других пользователей. Когда один пользователь публикует новый пост, все его подписчики получают уведомление.

class Subject:
def __init__(self):
self._observers = []

def attach(self, observer):
self._observers.append(observer)

def notify(self, message):
for observer in self._observers:
observer.update(message)

class User:
def update(self, message):
print(f"Новый пост: {message}")



tgoop.com/CScience1/3125
Create:
Last Update:

Паттерн Observer (Наблюдатель)

Observer позволяет объектам подписываться на события другого объекта. Когда событие происходит, все подписчики уведомляются автоматически.

Пример:
Представьте, что у вас есть социальная сеть, где пользователи могут подписываться на обновления других пользователей. Когда один пользователь публикует новый пост, все его подписчики получают уведомление.

class Subject:
def __init__(self):
self._observers = []

def attach(self, observer):
self._observers.append(observer)

def notify(self, message):
for observer in self._observers:
observer.update(message)

class User:
def update(self, message):
print(f"Новый пост: {message}")

BY Computer Science


Share with your friend now:
tgoop.com/CScience1/3125

View MORE
Open in Telegram


Telegram News

Date: |

You can invite up to 200 people from your contacts to join your channel as the next step. Select the users you want to add and click “Invite.” You can skip this step altogether. How to Create a Private or Public Channel on Telegram? Polls Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. How to build a private or public channel on Telegram?
from us


Telegram Computer Science
FROM American