V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
alexapollo
V2EX  ›  问与答

多态与泛型的关系?

  •  
  •   alexapollo · Mar 11, 2014 · 3847 views
    This topic created in 4442 days ago, the information mentioned may be changed or developed.
    看完了多态的维基百科 http://en.wikipedia.org/wiki/Polymorphism_(computer_science)
    在Parametric polymorphism一段里提到
    “Parametric polymorphism is also available in several object-oriented languages, where it often goes under the name "generics" (for example, Java) or "templates" (C++ and D):”
    我的理解就是多态的Parametric部分就包含了泛型?不是很肯定,不知道这个理解有没有问题?
    4 replies    1970-01-01 08:00:00 +08:00
    ivanlw
        1
    ivanlw  
       Mar 11, 2014 via iPhone
    最近准备面试刚好看到这个:Polymorphism 是OOD的三个principles之一,是理论;generics和templates是不同programming languages的具体实现。
    顺便推荐一篇好文: http://beginnersbook.com/2013/03/oops-in-java-encapsulation-inheritance-polymorphism-abstraction/
    SoloCompany
        2
    SoloCompany  
       Mar 11, 2014 via iPad
    读完这段wiki,感觉是这样对多态进行了分类,首先是adhoc overload,就是通常教科书说说的 overload,第二个说的 parameterize overload 就是范型覆盖,最后一个subtyping 其实应该更类似与是对override的描述,老的教科书一般只提及overload和override,没有提及范型这种和overload有点接近的概念
    alexapollo
        3
    alexapollo  
    OP
       Mar 13, 2014
    @ivanlw 三个principle?求推荐面试书籍~
    alexapollo
        4
    alexapollo  
    OP
       Mar 13, 2014
    @SoloCompany 对,ad hoc/parametric/subtyping三种polymorphism,代指了overloading/generic/override(implement),看起来泛型在此下是多态的子集
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1065 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:36 · PVG 02:36 · LAX 11:36 · JFK 14:36
    ♥ Do have faith in what you're doing.