-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriverObserver.py
More file actions
32 lines (24 loc) · 779 Bytes
/
DriverObserver.py
File metadata and controls
32 lines (24 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Design_Patterns.Behavioral.PublishSubscribe import PublishAndSubscribe
pub = PublishAndSubscribe.Publisher() # Initialized Publisher
"""
** Subscribers: **
We have initialized 3 subscribers with specified name
"""
bob = PublishAndSubscribe.Subscriber('Bob')
alice = PublishAndSubscribe.Subscriber('Alice')
john = PublishAndSubscribe.Subscriber('John')
pub.register(bob)
pub.register(alice)
pub.register(john)
pub.dispatch("It's lunchtime!")
pub.unregister(john)
pub.dispatch("Time for dinner ")
# ---- OUTPUT: ---- :
#
# Alice got message "It's lunchtime!"
# Bob got message "It's lunchtime!"
# John got message "It's lunchtime!"
# Alice got message "Time for dinner "
# Bob got message "Time for dinner "