多态性-仅用两个句子定义 [英] Polymorphism - Define In Just Two Sentences

查看:62
本文介绍了多态性-仅用两个句子定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了其他定义和解释,但没有一个让我满意.我想看看是否有人可以在不使用任何代码或示例的情况下最多在两个句子中定义多态性.我不想听到所以你有一个人/汽车/开罐器..."或这个词是如何衍生的(没人知道您知道poly和morph的含义).如果您对多态性有一个很好的掌握,并且英语水平很好,那么您应该能够以简短而密集的定义来回答这个问题.如果您的定义准确地定义了多态性,但是它的密度如此之高以至于需要进行多次读取,那么这正是我所要寻找的.

为什么只有两个句子?因为定义简短而智能.解释很长,其中包含示例和代码.在这里寻找解释(这些页面上的答案对我的问题并不满意):

多态vs覆盖vs重载
尝试尽可能简单地描述多态

我为什么要问这个问题?因为有人问我同样的问题,我发现我无法给出令人满意的定义(按照我的标准,这是很高的标准).我想看看这个网站上有没有头脑的人能做到这一点.

如果您真的不能满足两个句子的要求(这是一个很难定义的主题),那么再走一遍也可以.想法是要有一个定义,该定义实际上定义什么是多态性,而不解释它的用途或用法(得到差异吗?).

解决方案

多态性允许某种合同的表达,可能有许多类型以不同的方式(无论是否通过类继承)实现该合同(每种合同均根据其类型)自己的目的. 使用的代码,该合同不必(*)不必关心涉及哪个实现,而只是要遵守该合同.

(*)无论如何,在理想情况下-显然,调用代码经常是非常故意地选择了合适的实现!

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?).

解决方案

Polymorphism allows the expression of some sort of contract, with potentially many types implementing that contract (whether through class inheritance or not) in different ways, each according to their own purpose. Code using that contract should not(*) have to care about which implementation is involved, only that the contract will be obeyed.

(*) In the ideal case, anyway - obviously quite often the calling code has chosen the appropriate implementation very deliberately!

这篇关于多态性-仅用两个句子定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆