装饰的功能@staticmethod和装饰的功能有什么区别@classmethod?
我正在努力了解它的用法super().从它的外观来看,可以创建两个子类,就好了.
我很想知道以下2个孩子班级之间的实际差异.
class Base(object):
def __init__(self):
print "Base created"
class ChildA(Base):
def __init__(self):
Base.__init__(self)
class ChildB(Base):
def __init__(self):
super(ChildB, self).__init__()
ChildA()
ChildB()
Run Code Online (Sandbox Code Playgroud) 是否有可能在python中有静态类变量或方法?这样做需要什么语法?
控制反转(或IoC)在第一次遇到时会非常混乱.
有人可以在OOP上下文中提供方法与函数的简单解释吗?
为什么喜欢构图而不是继承呢?每种方法都有哪些权衡取舍?什么时候应该选择继承而不是作文?
有人可以向我解释@classmethod和@staticmethodpython中的含义吗?我需要知道差异和意义.
据我所知,@classmethod告诉一个类,它是一个应该继承到子类的方法,或者......某种东西.但是,重点是什么?为什么不在不添加@classmethod或定义@staticmethod任何@定义的情况下定义类方法?
tl; dr: 我应该何时使用它们,为什么要使用它们,我应该如何使用它们?
我在C++方面非常先进,所以使用更高级的编程概念应该不是问题.如果可能的话,请随意给我一个相应的C++示例.
oop ×10
python ×5
class ×3
inheritance ×2
methods ×2
aggregation ×1
class-method ×1
composition ×1
function ×1
interface ×1
metaclass ×1
php ×1
scope ×1
static ×1
super ×1
terminology ×1