10-Java接口技术分析.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
10-Java接口技术分析

* * * * * * * * * * * * * InterfaceDemo.java ch10.creditCard ch10.location ch10.moneyFundMarket OOP思想总结 OOP基本特征 定义 具体实现方式 优势 封装 隐藏实现细节,对外提供公共的访问接口 属性私有化、添加公有的setter、getter方法 增强代码的可维护性,数据的安全性 继承 从一个已有的类派生出新的类,子类具有父类的一般特性,以及自身特殊的特性 继承需要符合的关系:is-a,通过使用extends关键字实现继承,使用super调用父类的成员 1、实现抽象(抽出像的部分) 2、增强代码的可复用性 多态 同一个实现接口,使用不同的实例而执行不同操作 通过Java接口/继承来定义统一的实现接口;通过方法重写为不同的实现类/子类定义不同的操作 增强代码的可扩展性、可维护性 代码阅读 public interface Introduceable { public String detail(); public void introduction(){ detail(); } private void showMessage(); void speak(); } Java接口中的方法必须是public Java接口中不能有方法体实现 编译器会自动加上public修饰符 请指出下列Java代码中的错误 工厂设计模式 工厂设计模式也是最常用的设计模式之一 它的核心思想是通过专门定义一个类,来负责创建其他类的实例 被创建的实例通常都具有共同的父类 工厂设计模式 public interface Fruit { public void eat(); } class Apple implements Fruit{ public void eat() { System.out.println(“吃苹果”); } } class Orange implements Fruit{ public void eat() { System.out.println(“吃橘子”); } } 工厂设计模式 public class EatDemo { public static void main(String args[ ]) { Fruit f = new Apple(); f.eat(); } } 当要吃其它类型的水果时,就要修改代码 有缺陷吗? 工厂设计模式 工厂设计模式 public interface Fruit { public void eat(); } class Apple implements Fruit{ public void eat() { System.out.println(“吃苹果”); } } class Orange implements Fruit{ public void eat() { System.out.println(“吃橘子”); } } 工厂设计模式 Class Factory { public static Fruit getInst(int arg) { Fruit f; if(arg==1) f = new Apple(); if(arg==2) f = new Orange(); return f; } } 工厂设计模式 public class EatDemo { public static void main(String args[ ]) { Fruit f; Scanner input = new Scanner(System.in); int arg = input.nextInt(); f = Factory.getInst(arg); input.close(); f.eat(); } } 开发任务 开发需求 (1)信用卡分为VISA, AMERICANEXPRESS, MASTERCARD三种类型,为每种信用卡写一个类 (2)每个信用卡类都有一个处理POS机刷卡的方法swipeCard_POS() (3)请使用接口技术和工厂模式实现开发需求 适配器设计模式 Java要求实现接口的类必须覆写接口中的所有抽象类 当一个接口中定义了大量的抽象方法,而实现该接口的子类只需要其中的一部分时

文档评论(0)

1520520 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档