鱼C论坛

 找回密码
 立即注册
查看: 2340|回复: 9

求帮助,完全看不懂!

[复制链接]
发表于 2014-9-2 11:37:10 | 显示全部楼层 |阅读模式
40鱼币
  1. class PlugIn(object):
  2.     def __init__(self):
  3.         self._exported_methods = []
  4.         
  5.     def plugin(self, owner):
  6.         for f in self._exported_methods:
  7.             owner.__dict__[f.__name__] = f

  8.     def plugout(self, owner):
  9.         for f in self._exported_methods:
  10.             del owner.__dict__[f.__name__]

  11. class AFeature(PlugIn):
  12.     def __init__(self):
  13.         super(AFeature, self).__init__()
  14.         self._exported_methods.append(self.get_a_value)

  15.     def get_a_value(self):
  16.         print ('a feature.')

  17. class BFeature(PlugIn):
  18.     def __init__(self):
  19.         super(BFeature, self).__init__()
  20.         self._exported_methods.append(self.get_b_value)

  21.     def get_b_value(self):
  22.         print ('b feature.')

  23. class Combine:pass

  24. c = Combine()
  25. AFeature().plugin(c)
  26. BFeature().plugin(c)

  27. c.get_a_value()
  28. c.get_b_value()
复制代码
这是小甲鱼的课程,谁能帮帮忙,完全看不懂呀!

谁能帮帮忙一句句注释下?

最佳答案

查看完整内容

刚看完39讲。。有啥不对的还请指正。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-2 11:37:11 | 显示全部楼层
  1. class PlugIn(object):                       #定义一个PiugIn的类
  2.     def __init__(self):                         #定义__init__方法
  3.         self._exported_methods = []  #设置局部变量 _exported_methods
  4.         
  5.     def plugin(self, owner):               #定义plugin的方法
  6.         for f in self._exported_methods:             #把列表都列出来。
  7.             owner.__dict__[f.__name__] = f        #__dict__用于扩展对象方法。
  8.     def plugout(self, owner):                       #这个不知道什么用。。删掉完全可以运行。
  9.         for f in self._exported_methods:
  10.             del owner.__dict__[f.__name__]


  11. class AFeature(PlugIn):                     #定义AFeature的类是PlugIn的子类
  12.     def __init__(self):                          #定义__init__方法
  13.         super(AFeature, self).__init__()    #继承父类的方法
  14.         self._exported_methods.append(self.get_a_value)    #_exported_methods列表里添加get_a_value

  15.     def get_a_value(self):              #定义get_a_value方法
  16.         print ('a feature.')                #方法是打印打印a feature.

  17. class BFeature(PlugIn):                 #定义BFeature类是PlugIn的子类
  18.     def __init__(self):                         #定义__init__方法
  19.         super(BFeature, self).__init__()  #继承父类的方法
  20.         self._exported_methods.append(self.get_b_value) #_exported_methods列表里添加get_b_value

  21.     def get_b_value(self):       #定义get_b_value方法
  22.         print ('b feature.')        #方法是打印打印b feature.

  23. class Combine:pass          #定义Combine类,里面什么都木有。。

  24. c = Combine()               #实例对象c
  25. AFeature().plugin(c)     #使c扩展对象方法。
  26. BFeature().plugin(c)     #使c扩展对象方法。
  27. c.get_a_value()            #调用方法。
  28. c.get_b_value()
复制代码

360截图20140902131003564.jpg 刚看完39讲。。有啥不对的还请指正。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-4 09:58:42 | 显示全部楼层
好难
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-4 10:02:01 | 显示全部楼层
实在看不懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-5 20:56:59 | 显示全部楼层
迷茫:sad~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-6 16:53:46 | 显示全部楼层
还没学到呢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-7 10:26:00 | 显示全部楼层
看起来不错,希望有人回答
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-7 11:59:27 | 显示全部楼层
呵呵,有点看看不懂,,,在学习当中
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-11 16:12:57 | 显示全部楼层
两包烟的钱,把不了妹买不了田,不如拿来支持小甲鱼推出更多原创教学视频!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-6-5 10:58:53 | 显示全部楼层
表示我还没学到那里
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 15:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表