paper help# Biology - 生物学
J*n
1 楼
不少书上将overloading说成是polymorphism的一种实现方式,但是wiki上有这段话
"Polymorphism is only concerned with the application of specific
implementations to an interface or a more generic base class. Method
overloading refers to methods that have the same name but different
signatures inside the same class. Method overriding is where a subclass
replaces the implementation of one or more of its parent's methods.
Neither method overloading nor method overriding are by themselves
implementations of polymorphism"
不过,这之前确实有这样一句话“(Subtype) polymorphism is not the same as method
overloading or method overriding [1], (that is known instead as ad-hoc polymorphism [2])”
从定义上看,polymorphism is the ability to allow objects of different types to
response to the same message, but display different behaviors.
我的理解是,多态主要表现在声明一个父类或者接口变量,然后将子类或者实现了那个接口
的对象赋给该变量时,不同的对象能对同个消息(或者方法调用)表现出不同的动作,从而
表现出多态,这让我们在写代码时通过对父类或者接口编程,能容易的实现程序的可扩展性
和可维护性。这同时也是动态绑定的实现方式。而重载并不需要通过父类或者接口变量来实
现,不具备上述的优点,所以称不上多态。
不知道大家对这个问题怎么理解
"Polymorphism is only concerned with the application of specific
implementations to an interface or a more generic base class. Method
overloading refers to methods that have the same name but different
signatures inside the same class. Method overriding is where a subclass
replaces the implementation of one or more of its parent's methods.
Neither method overloading nor method overriding are by themselves
implementations of polymorphism"
不过,这之前确实有这样一句话“(Subtype) polymorphism is not the same as method
overloading or method overriding [1], (that is known instead as ad-hoc polymorphism [2])”
从定义上看,polymorphism is the ability to allow objects of different types to
response to the same message, but display different behaviors.
我的理解是,多态主要表现在声明一个父类或者接口变量,然后将子类或者实现了那个接口
的对象赋给该变量时,不同的对象能对同个消息(或者方法调用)表现出不同的动作,从而
表现出多态,这让我们在写代码时通过对父类或者接口编程,能容易的实现程序的可扩展性
和可维护性。这同时也是动态绑定的实现方式。而重载并不需要通过父类或者接口变量来实
现,不具备上述的优点,所以称不上多态。
不知道大家对这个问题怎么理解