# -*- coding: utf-8 -*-
"""
Created on Wed Mar 28 18:50:47 2018
@author: mz
"""
#observer
class Boss(object):
def __init__(self):
self.obj = [];
def Attach(self, employee):
self.obj.append(employee)
def In(self):
print("Boss in->")
self.Notify(0);
def Out(self):
print("Boss out->")
self.Notify(1);
def Notify(self, tag):
if 0 == tag:
for o in self.obj:
o.Work()
else:
for o in self.obj:
o.Relax()
#subject
class Employee(object):
def Work(self):
pass
def Relax(self):
pass
class Manager(Employ
Python 观察者模式
最新推荐文章于 2024-08-17 21:25:52 发布
