zoukankan      html  css  js  c++  java
  • 多态本质:多个对象共享同一接口 多态本质是共享接口

    所谓的多态是将类似的不同实现统一到一个(组)接口的能力;

    涉及到两个方面:1)抽象能力;2)面向接口(忽略载体、对象)。

    Polymorphism is the ability of the programmer to write methods of the same name that do different things for different types of objects, depending on the needs of those objects.

    Polymorphism is a long word for a very simple concept.

    Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

    The beauty of polymorphism is that the code working with the different classes does not need to know which class it is using since they’re all used the same way. A real world analogy for polymorphism is a button. Everyone knows how to use a button: you simply apply pressure to it. What a button “does,” however, depends on what it is connected to and the context in which it is used — but the result does not affect how it is used. If your boss tells you to press a button, you already have all the information needed to perform the task.

    In the programming world, polymorphism is used to make applications more modular and extensible. Instead of messy conditional statements describing different courses of action, you create interchangeable objects that you select based on your needs. That is the basic goal of polymorphism.

    Polymorphism results from the fact that every class lives in its own namespace. The names assigned within a class definition don’t conflict with names assigned anywhere outside it. This is true both of the instance variables in an object’s data structure and of the object’s methods:

  • 相关阅读:
    普通类型(Trivial Type)和标准布局类型(Standard-layout Type)以及POD类型
    设计模式
    网络相关的学习和命令总结
    sheel命令学习和工作总结。
    Makefile的学习
    [UI基础][实现]九宫格之应用程序管理
    [嵌入式][分享][交流]发布一个消息地图的模块
    [UI基础][不会说话的汤姆猫]
    [UI基础][QQ登陆界面]
    volatile的陷阱
  • 原文地址:https://www.cnblogs.com/feng9exe/p/8303789.html
Copyright © 2011-2022 走看看