- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
OOP-1.Polymorphism
System pre-defined overloading operators The most early occurrence of overloading. Supported by almost all programming languages. Typical operators overloading: +: int ? int ? int +: double ? double ? double +: Both arithmetic operation and string concatenation. x / y: Both integral and floating point division. 簿篓乡屈汝棕悬吁谬甭吊庭闻扣鲤咳豌逻验船漆露识喻颁险详券魄计军盆OOP-1.Polymorphism面向对象 User defined overloading operators Different language design philosophy. Supported by: C++, Eiffel, ... Not supported by Java. Two viewpoints of operation x + y. Normal functions with special syntax: operator +(x, y) Operations on object x with a special name: x.operator +(y) Hybrid OOPLs such as C++ support both. Pure OOPLs such as Eiffel support only the last form. 恐荧亩便吟咸烈恳猛肉差生辰呈落呜点雪疥离栓蓑桩庭瓣怎攫讨狰俺第函OOP-1.Polymorphism面向对象 User defined overloading operators in C++ Two viewpoints of x + y: (1) A member of object x: x.operator+(y) COMPLEX operator+(const COMPLEX other) const; (2) A normal function and a friend: operator+(x, y) friend COMPLEX operator+( const COMPLEX left, const COMPLEX right); 冻间思枫岔褒佃著钎类旭辜案登蔚失性天选惧瘸言秀敛砖权纷浇郑淌堕诛OOP-1.Polymorphism面向对象 Trade-offs of system pre-defined overloading operators Languages tending to be more agile: C (? C++ ? Java) x / y Languages tending to be more rigorous: Pascal x div y x / y Trade-offs of user defined overloading operators Supported by languages tending to agility: C++. Rejected by languages tending to rigorousness: Java Language Design Philosophy 耳蹲悲匙酸槽搬录喧吝茸曳盖秧祸祁埂框篷殿挨啃匿换迫沙交棺厨拒蓟浑OOP-1.Polymorphism面向对象 Generic Classes (or Parameterized Classes) Provide formal generic parameters for a class. Why Generics ? Strong typing languages need generics. Although strong typing makes a program safer, it leads to lack of agility. Generics compromise the conflicts between agility and safeness. Trade-off in software design. Generics 捶劲毁旺汹收访拖翟候幻名戊羡醚腻呜亢焦柞枢垮揉夸隔拈扒逆稳刮协陆OOP-1.Polymorphism面向对象 class TABLE[G] feature ... put(element: G, key
文档评论(0)