- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
cs1311lecture22wdl.ppt
PolymorphismPure Object Oriented Programming Announcements Office Hours next Tuesday, April 4, 2000 will be from 1:00 - 2:00 p.m. instead of 3:00 - 4:00 p.m. On the homework that’s due Friday Problem 2 requires inheritance! Polymorphism Scenarios A veterinarians algorithm might have a list of animals, but each one needs different food or care… we want ONE information system to track all of this without complex logic for each individual kind of animal. A car dealership sells many different types of cars with different features, but each has a price and quantity in stock. A registration system might treat in-state students differently from out-of-state students, graduate students differently from undergraduates, etc. A graphical user interface (GUI) e.g. Windows needs to puts lots of simlar widgets on screen... Motivation We’d like to be able to manage objects of different kinds of classes. Since classes within a class hierarchy often share common methods and attributes, we’d like to make use of this fact to make our algorithms simpler. Polymorphism Defined The ability to take on different forms. Manipulate objects of various classes, and invoke methods on an object without knowing that object’s type. A Class Hierarchy A Polymorphic Example Polymorphism Explained MyAnimal - MyMutt seems incorrect. The left and right hand side of the assignment seem to not match; or do they? Since Mutt inherits from Dog, and Dog inherits from Animal, then MyMutt is at all times a Mutt, a Dog, and an Animal. Thus the assignment statement is perfectly valid. This makes logical (“real world”) sense. An Illegal Example We are able to assign an object of a sub-class into an object of a super-class as in: MyAnimal - MyMutt But the reverse is not true. We can’t assign a superclass object into a sub-class object. MyMutt - MyAnimal // illegal Method Calls and Polymorphism Assume the Dog class inherits the Animal class, redefining the “MakeNoise” method. Consider the followin
您可能关注的文档
- smallanimalresourcelist-animalfriendsoflansdowne.doc
- commonquestionsofbuyersstratacorporation-pemberton.doc
- mynewpet-primaryresources.ppt
- informationforcatowners-maggie'srescue.doc
- pet-friendlyshelters-floridastateagriculturalresponseteam.ppt
- boardingcontract-dogs-a-jammin.doc
- atthepetshop-primaryresources.ppt
- dogs-arkveterinarypractice.doc
- valueofpet-ctinhepatocellularcarcinoma.ppt
- thepetsupplycrisis-containerrecyclinginstitute.ppt
- 贵州贵州省建设投资集团有限公司招聘考试真题附答案详解(研优卷).docx
- 河南南阳师范学院2021年招聘25名硕士研究生冲刺卷一(附答案与详解)及答案详解(名校卷).docx
- 陕西延长石油 (集团) 有限责任公司 所属单位招聘笔试题库及答案详解(必刷).docx
- 贵州民航产业集团有限公司招聘笔试题库含答案详解(基础题).docx
- 广汉市2025年公开招聘社区专职工作者(125人)考试备考题库含答案详解(考试直接用).docx
- 邢台市水务发展集团有限公司招聘真题附答案详解(实用).docx
- 新华保险总部人力资源部(党委组织部)招聘笔试题库含答案详解(预热题).docx
- 贵州苔茶产业发展集团有限公司招聘笔试题库含答案详解(b卷).docx
- 广汉市2025年公开招聘社区专职工作者(125人)考试备考题库附答案详解(综合题).docx
- 贵州城乡产业发展集团有限公司招聘笔试题库附答案详解(实用).docx
文档评论(0)