# -*- coding: utf-8 -*-
"""
Created on Thu Mar 15 12:01:02 2018
@author: mz
"""
class Phone(object):
def setGame(self, rhs):
self.game = rhs
class IOSPhone(Phone):
def playGame(self):
print("***IOS phone***")
self.game.play()
class AndroidPhone(Phone):
def playGame(self):
print("***Android phone***")
self.game.play()
class IGame(object):
def play(self):
pass
class WYGame(IGame):
def play(self):
print("play game of wang yi \r\n")
class TXGame(IGame):
def play(self):
print("play game of teng xun \r\n")
if "__main__" == __name__:
iphone = IOSPhone()
aphone = AndroidPhone()
iphone.setGame(WYGame())
iphone.playGame();
iphone.setGame(TXGame())
iphone.playGame();
aphone.setGame(WYGame())
aphone.playGame();
aphone.
Python 桥接模式
最新推荐文章于 2024-07-15 03:34:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)