【发布时间】:2009-05-25 04:12:43
【问题描述】:
我正在努力在 Python 中实现 Bridge 设计模式(或适配器等替代方案)
我希望能够编写这样的代码来根据提供的 URL 转储数据库模式:
urls = ['sqlite://c:\\temp\\test.db', 'oracle://user:password@tns_name'];
for url in urls:
db = Database(url);
schema = db.schema()
我的类定义为
class Database():
def __init__(self, url):
self.db_type = string.split(self.url, "://")[0]
class Oracle():
def schema(self):
# Code to return Oracle schema
class SQLite():
def schema(self):
# Code to return SQLite schema
如何将这 3 个类“粘合”在一起,以便正确执行第一个代码块?我在 Google 上四处搜索,但一定是度过了充实的一天,因为我并没有想到它......
提前致谢
【问题讨论】: