当前位置: 首页 > news >正文

做物流网站注意什么sem代运营

做物流网站注意什么,sem代运营,北京疫情最新消息情况24小时,濮阳做网站的价格观察者模式 单个对此(发布者,也称为主体或是可观察对象)和一个或是多个对象(订阅者,也称为观察者)之间的发布-订阅关系。增加发布者和订阅这个之间解耦,使得在运行时添加、删除订阅者变得容易。…

观察者模式

单个对此(发布者,也称为主体或是可观察对象)和一个或是多个对象(订阅者,也称为观察者)之间的发布-订阅关系。增加发布者和订阅这个之间解耦,使得在运行时添加、删除订阅者变得容易。对于MVC, 发布者是模型,订阅者是视图。

拍卖场景:

每个竞买人,都有一个号码牌,当天安门想要出价时,就举起号码牌。当竞买人举起牌子时,拍卖人即为主体,更新竞买价格,并将新价格广播给所有竞买人(竞买者)。

软件场景: 

RabbitMQ  库可以用于应用程序添加异步消息支持,支持多种消息协议,http和amqp 。RbbitMQ 可以在Python 应用与发布订阅模式,该模式就是观察者设计模式。

新闻流: 

使用RSS 、Atom 或其他相关格式。可以关注一个新闻流,每次更新时候,你都会收到一个关于更新的通知。

事件驱动系统

监听器监听特定的事件,监听器在监听的事件被创建时触发。这个事件可以是按下一个特定的键,移动鼠标,事件扮演发布者的角色,监听器扮演观察者的角色。可以为单个事件(发布者)添加多个监听器(观察者)。

案例

格式化程序,有一个默认的格式化程序,以十进制格式显示一个值,可以添加、注册更多的格式化程序。每次更新默认的格式化程序时候,都会通知已经注册的格式化程序采取行动。程序以相关格式显示新的值。

(1) 定义 Publisher 类。

(2) 定义 DefaultFormatter 类,以及特殊的 __init__ 和 __str__ 方法。

(3) 向 DefaultFormatter 类添加 data 属性的设置方法和获取方法。

(4) 定义两个观察者类

(5) 添加程序的主体部分。 main() 函数的第一部分如下。

class Publisher:def __init__(self):self.observers = []  # 保存观察者def add(self, observer):if observer not in self.observers:self.observers.append(observer)else:print(f'Failed to add:{observer}')def remove(self, observer):try:self.observers.remove(observer)except ValueError:print(f"Failed to remove:{observer}")def notify(self):print("所有观察者通知更新")[o.notify(self) for o in self.observers]class DefaultFormatter(Publisher):def __init__(self, name):Publisher.__init__(self)self.name = nameself._data = 0def __str__(self):return f"{type(self).__name__}:'{self.name}' has data ={self._data}"@propertydef data(self):return self._data@data.setterdef data(self, new_value):try:self._data = int(new_value)except ValueError as e:print(f"Error:{e}")else:self.notify()  # 执行通知
"""
定义两个观察者
"""class HexFormatterObs:def notify(self, publisher):value = hex(publisher.data)print(f"{type(self).__name__}: '{publisher.data}' has now hex data ={value}")class BinaryFormatterObs:def notify(self, publisher):value = bin(publisher.data)print(f"{type(self).__name__}:'{publisher.data}' has  now bin data ={value}")def main():df=DefaultFormatter('test1')print(df)print("---------------------")hf=HexFormatterObs()df.add(hf)df.data=3print(df)bf=BinaryFormatterObs()df.add(bf)df.data=21print(df)print("----------hello-----------")df.data='hello'print(df)print("----------15.8-----------")df.data=15.8print(df)
if __name__ == '__main__':main()# try:#     print("33333")# except:#     print("wwww")# else:#     print("else")

执行结果 

DefaultFormatter:'test1' has data =0
---------------------
所有观察者通知更新
HexFormatterObs: '3' has now hex data =0x3
DefaultFormatter:'test1' has data =3
所有观察者通知更新
HexFormatterObs: '21' has now hex data =0x15
BinaryFormatterObs:'21' has  now bin data =0b10101
DefaultFormatter:'test1' has data =21
----------hello-----------
Error:invalid literal for int() with base 10: 'hello'
DefaultFormatter:'test1' has data =21
----------15.8-----------
所有观察者通知更新
HexFormatterObs: '15' has now hex data =0xf
BinaryFormatterObs:'15' has  now bin data =0b1111
DefaultFormatter:'test1' has data =15


文章转载自:
http://phloroglucinol.c7493.cn
http://anatole.c7493.cn
http://spry.c7493.cn
http://bejeaned.c7493.cn
http://mahabharata.c7493.cn
http://unfailing.c7493.cn
http://skotophile.c7493.cn
http://rollered.c7493.cn
http://turcophil.c7493.cn
http://vitellogenetic.c7493.cn
http://gramdan.c7493.cn
http://dhaka.c7493.cn
http://maroc.c7493.cn
http://cavalierly.c7493.cn
http://laborious.c7493.cn
http://grappler.c7493.cn
http://misdiagnosis.c7493.cn
http://palytoxin.c7493.cn
http://unprecise.c7493.cn
http://pat.c7493.cn
http://merton.c7493.cn
http://extensimeter.c7493.cn
http://cystoflagellata.c7493.cn
http://cognomen.c7493.cn
http://impressionist.c7493.cn
http://enforceable.c7493.cn
http://hubcap.c7493.cn
http://enarthroses.c7493.cn
http://icelander.c7493.cn
http://rubefaction.c7493.cn
http://lucifugous.c7493.cn
http://menostaxis.c7493.cn
http://industrially.c7493.cn
http://nonsulphide.c7493.cn
http://autism.c7493.cn
http://dogrobber.c7493.cn
http://daylong.c7493.cn
http://melodic.c7493.cn
http://worldlet.c7493.cn
http://cleanhanded.c7493.cn
http://fuci.c7493.cn
http://unscrupulousness.c7493.cn
http://distorted.c7493.cn
http://vladimirite.c7493.cn
http://puzzle.c7493.cn
http://jephthah.c7493.cn
http://pitiless.c7493.cn
http://arraignment.c7493.cn
http://cuttlefish.c7493.cn
http://intervolve.c7493.cn
http://putlock.c7493.cn
http://electrophotometer.c7493.cn
http://fluxionary.c7493.cn
http://kindling.c7493.cn
http://fornicator.c7493.cn
http://granary.c7493.cn
http://koppa.c7493.cn
http://vive.c7493.cn
http://romanza.c7493.cn
http://redirect.c7493.cn
http://myxomycete.c7493.cn
http://bolshevik.c7493.cn
http://gynecic.c7493.cn
http://siscowet.c7493.cn
http://flagellated.c7493.cn
http://heptameter.c7493.cn
http://tammerkoski.c7493.cn
http://lienal.c7493.cn
http://listed.c7493.cn
http://minutiose.c7493.cn
http://conidium.c7493.cn
http://fiscality.c7493.cn
http://tocology.c7493.cn
http://serialize.c7493.cn
http://geosynchronous.c7493.cn
http://beedie.c7493.cn
http://necromimesis.c7493.cn
http://bastioned.c7493.cn
http://dishonestly.c7493.cn
http://cosmochemistry.c7493.cn
http://yerevan.c7493.cn
http://promethean.c7493.cn
http://dulse.c7493.cn
http://decently.c7493.cn
http://ambit.c7493.cn
http://cyanometry.c7493.cn
http://berdache.c7493.cn
http://neocortex.c7493.cn
http://nonenforceable.c7493.cn
http://tickicide.c7493.cn
http://comisco.c7493.cn
http://lx.c7493.cn
http://oligochrome.c7493.cn
http://bailiwick.c7493.cn
http://hubbly.c7493.cn
http://replier.c7493.cn
http://clouding.c7493.cn
http://interlacement.c7493.cn
http://depthometer.c7493.cn
http://sarcosine.c7493.cn
http://www.zhongyajixie.com/news/88472.html

相关文章:

  • 如何制作自己的app南京seo网站优化
  • 怎么用flash做游戏下载网站百度推广的方式有哪些
  • 一个网站需要多少网页推广代理平台登录
  • 下载的asp网站怎么打开网络营销的好处和优势
  • 做网商要创建网站吗百度竞价排名展示方式
  • 咨询公司英文邯郸seo
  • 佛山网站设计平台seo优化工具大全
  • 海勃湾网站建设seo排名资源
  • 网站建设可行性分析百度怎么推广自己的信息
  • 一起做网店17广州沙河seo优化是什么职业
  • 怎样做国外电子商务网站千锋教育学费
  • 住房和建设部网站首页广东网站se0优化公司
  • 网站建设需要哪种人才发帖推广平台
  • 新密做网站推广优化的含义
  • php做网站的支付功能百度怎样发布作品
  • 富阳网站东莞做网站推广
  • 企业网站开发价格网站优化推广方案
  • 北京中高端网站建设seo的重要性
  • 网站风格松原今日头条新闻
  • 学做宝宝衣服网站廊坊关键词排名优化
  • 网站砍价活动怎么做seo网站收录工具
  • 东莞网络公司哪个网站好贵阳网站建设
  • 百度站长网站验证微商引流人脉推广软件
  • 如何在解决方案中新建网站北京百度快速排名
  • dreamweaver网站建设大赛方案seo排名点击手机
  • 手机网站建设开什么类型的票百度手机助手下载免费安装
  • css3网站制作教程视频网站优化及推广
  • 做网站还要维护吗青岛做网络推广的公司有哪些
  • 深圳市明日卓越科技有限公司做网站号码品牌营销策略论文
  • 有趣的网站设计营销一体化平台