- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
* AnimalKingdom class cannot be instantiated all classes that extend AnimalKingdom must implement eat or else must also be declared abstract * This maps with C++, may have been an early design. Interfaces will be introduced later. * 利用接口可实现多重继承(可同时实现多个接口) 接口的作用和抽象类 类似,指定原型,不直接定义方法的内容. 关键字implement用 来实现方法,即在使用时要用给出方法的实际内容 接口中的方法和变量 是public的 * Adapter适配器模式是一种结构型模式,主要应对:由于应用环境的变化,常常需要将“一些现存的对象”放在新的环境中应用,但是,新环境要求的接口是现存对象所不满足的。 E.g.我们常使用的移动硬盘,无论是笔记本硬盘还是台式机硬盘,对于数据的传输都不使用Usb的数据线,外接的硬盘盒就是将原来的硬盘数据传输方式适合Usb数据线。 将一个类的接口转换成客户希望的另一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的类可以一起工作。 If the classes you want to reuse can not be modified, write code to take the interface that you have and produce the interface that you need. * t(h); // Treat it as a CanFight u(h); // Treat it as a CanSwim v(h); // Treat it as a CanFly w(h); // Treat it as an ActionCharacter Actually, there is something not as expected as the above treats. If there is implementation of method fight() in class Hero, the method call in main method t and w will call the same method. So, how to deal with these name thing? * Interfaces may be nested within classes and within other interfaces * Suppose that you have written a time server, which periodically notifies its clients of the current date and time. Write an interface that the server could use to enforce a particular protocol on its clients. * To make an object of the inner class anywhere except from within a non-static method of the outer class, you must specify the type of that object as OuterClassName.InnerClassName * Heres how to do a little object matchmaking of your own: * but nothing really happens until somebody makes an instance of BOTH classes... * A top-level nested class is little more than another way to control namespace. the inner object can access the private data of the outer object As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class
文档评论(0)