⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 component-example.py

📁 大型多人在线游戏开发,该书光盘上附带的源码
💻 PY
字号:
from twisted.python.components import getAdapter, registerAdapter, Interfaceclass IA(Interface):                    # Define an interface that implements     def a(self):                        # a sample method method, "a".        "A sample method."class A:                                # define an adapter class    __implements__ = IA                 # that implements our IA interface    def __init__(self, original):       # keep track of the object being wrapped        self.original = original    def a(self):                        # define the method required by our        print 'a',                      # interface, and have it print 'a'        self.original.b()               # then call back to the object we're adaptingclass B:                                # the hapless B class doesn't know anything    def b(self):                        # about its adapter, and it defines one        print 'b'                       # method which displays 'b'registerAdapter(A, B, IA)               # register A to adapt B for interface IAadapter = getAdapter(B(), IA, None)     # adapt a new B instance with an A instanceadapter.a()                             # call the method defined by interface IA

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -