Polymorphism - Define In Just Two Sentences [close

2019-01-04 15:40发布

I've looked at other definitions and explanations and none of them satisfy me. I want to see if anybody can define polymorphism in at most two sentences without using any code or examples. I don't want to hear 'So you have a person/car/can opener...' or how the word is derived (nobody is impressed that you know what poly and morph means). If you have a very good grasp of what polymorphism is and have a good command of English than you should be able to answer this question in a short, albeit dense, definition. If your definition accurately defines polymorphism but is so dense that it requires a couple of read overs, then that's exactly what I am looking for.

Why only two sentences? Because a definition is short and intelligent. An explanation is long and contains examples and code. Look here for explanations (the answer on those pages are not satisfactory for my question):

Polymorphism vs Overriding vs Overloading
Try to describe polymorphism as easy as you can

Why am I asking this question ? Because I was asked the same question and I found I was unable to come up with a satisfactory definition (by my standards, which are pretty high). I want to see if any of the great minds on this site can do it.

If you really can't make the two sentence requirement (it's a difficult subject to define) then it's fine if you go over. The idea is to have a definition that actually defines what polymorphism is and doesn't explain what it does or how to use it (get the difference?).

30条回答
放我归山
2楼-- · 2019-01-04 16:19

Polymorphism is ability of an object to appear and behave differently for the same invocation. ex: each animal appear and sound differently ( when you hit it :) )

查看更多
仙女界的扛把子
3楼-- · 2019-01-04 16:20

Polymorphism concept became a phenomenon lately. Here is the actual drift. Runtime defines which submethod should be invoked by a reference of a super class. Now, what does mean in practice? It means actually nothing. You can code simply without polymorphism. So, why? Because, if we haven't got the polymorphism, we had to memorize all the subclass functions definitions. Polymorphism saves us from this in practice.

You can define a list as follows:

List list = new List();

but if you check for IList, you can benefit of the interface as:

IList list = new List();

and use the IList reference freely. Assuming IList is also implemented in another class, you can use methods of that unknown class via again IList reference without trying to remember that class name. Marvelous, isn't it?

Now, more valuable information is coming:
Java is by default polymorphic, whereas .NET and C++ are not, in MS, you have to declare the base function virtual (and in .NET override keyword).

Also, there are 2 integral rules in polymorphism. One is inheritance (via interface impl. or via class extending) and the other is overriding. Without overriding, polymorphism doesn't exist. Note that method overloading (which always in a single class) is also a type of "minimalistic" polymorphism.

查看更多
走好不送
4楼-- · 2019-01-04 16:21

Polymorphism is a feature of programming languages that allows an object to be treated as an instance of its supertype.

查看更多
对你真心纯属浪费
5楼-- · 2019-01-04 16:22

Polymorphism is the ability of using different classes that implement a common interface (or extend a common base class) in a common way, without needing to now the specific implementation, and using only the methods available in the common interface.

Ie: In Java, as ArrayList and LinkedList both implement List, if you declare a variable as List, you can always perform the operations allowed in List, no matter which if you variable was instanced as an ArrayList or a LinkedList.

查看更多
你好瞎i
6楼-- · 2019-01-04 16:23

Polymorphism is declaring a uniform interface that isn't type aware, leaving implementation details to concrete types that implement the interface.

查看更多
聊天终结者
7楼-- · 2019-01-04 16:23

Polymorphism is a software coding abstraction where several different underlying entities (usually data, but nit always) all share a common interface which allows them to look and act identical at runtime. We use this as a development technique to enforce consistent behavior over a wide range of similar, but not identical instances with an absolute minimal implementation, thus reducing the expectation for bugs and inconsistencies.

Paul.

查看更多
登录 后发表回答