Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在Python中重构类?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有用Python编写的测试代码,使用类。在</p> <p>测试环境有两种类型的主机—应用程序运行的主机和运行存储组件的存储主机。在</p> <p>我有两个类,每个类代表主机类型:</p> <pre><code>class AppHost_Class(object): def __init_(self, ip_address): # etc. # This method handles interfacing with the application def application_service(self): # This method handles the virtual storage component def virtual_storage(self): # This method handles caching def cache_handling(self): class Storage_Server_Class(object): def __init_(self, ip_address): # This method handles interfacing with the storage process def storage_handling(self): # This method handles interfacing with the disk handling processes def disk_handling(self): </code></pre> <p>问题是拓扑结构可能会改变。在</p> <p>拓扑图1是: -应用程序主机运行 *应用程序流程 *虚拟存储进程 *缓存进程</p> <ul> <li>存储主机运行 <ul> <li>存储过程</li> <li>磁盘处理过程</li> </ul></li> </ul> <p>我当前的测试代码处理拓扑1</p> <p>但是,我们还希望支持另一种拓扑(拓扑#2)</p> <ul> <li><p>应用程序主机运行</p> <ul> <li>应用程序流程</li> </ul></li> <li><p>存储主机运行</p> <ul> <li>虚拟存储进程</li> <li>缓存进程</li> <li>存储过程</li> <li>磁盘处理过程</li> </ul></li> </ul> <p>如何重构这些类,以便对于拓扑1,类和它的方法是相同的,但是对于拓扑2,<code>Storage_Server_Class</code>从{<cd2>}获得一些方法?在</p> <p>我在想办一个这样的儿童班:</p> ^{pr2}$ <p>但我不想这样做,因为我不想<code>applcation_service</code>方法对<code>Both_Class</code>可用。在</p> <p>有没有办法把<code>AppHost_Class</code>中的几个方法映射到<code>Storage_Server_Class</code>?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>下面是一个类B的示例,它只共享在类a中定义的一个方法:</p> <pre><code>class A: def a1(self): pass def a2(self): pass class B: def __init__(self, instance_of_a): self.a2 = instance_of_a.a2 a = A() B(a) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
4 回答
Jupyter运行不同版本的卸载库?
3 回答
Jupyter运行指定的键盘快捷键
2 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
10 回答
Jupyter重新加载自定义样式
6 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
1 回答
jupyter错误:无法在随机林中将决策树视为png
4 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
6 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
9 回答
Jupyter隐藏数据帧索引,但保留原始样式
5 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
10 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
7 回答
Jupy上Python的读/写访问问题
7 回答
jupy上没有模块cv
9 回答
Jupy上的排序错误
2 回答
Jupy中bqplot图形的紧凑布局
7 回答
Jupy中matplotlib plot的连续更新
8 回答
Jupy中Numpy函数的文档
3 回答
Jupy中Pandas的自动完成问题
2 回答
jupy中Qt后端的Matplotlib动画
2 回答