Polymorphism(ポリモーフィズム)がよくわからない

Software Architecture

この説明が一番しっくりきた。

As the examples above illustrate, messages in Objective-C appear in the same syntactic positions as function calls in standard C. But, because methods “belong to” an object, messages behave differently than function calls.

In particular, an object has access only to the methods that were defined for it. It can’t confuse them with methods defined for other kinds of objects, even if another object has a method with the same name. This means that two objects can respond differently to the same message. For example, each kind of object sent a display message could display itself in a unique way. A Circle and a Rectangle would respond differently to identical instructions to track the cursor.

This feature, referred to as polymorphism, plays a significant role in the design of object-oriented programs. Together with dynamic binding, it permits you to write code that might apply to any number of different kinds of objects, without your having to choose at the time you write the code what kinds of objects they might be. They might even be objects that will be developed later, by other programmers working on other projects. If you write code that sends a display message to an id variable, any object that has a display method is a potential receiver.

http://www.toodarkpark.org/computers/objc/coreobjc.html#1329

本とか、あっちこっちの文献を見ていると、微妙にわかりづらい。

この文章のように、理論と実装を明確に分けて書いてほしい。

コメント