拓冰建站拓冰建站
首页 / 资讯中心 / 正文

设计模式:适配器模式(Adaptor Pattern)

/** * 适配器模式将一个类的接口转换成另一个类的接口让原本不兼容的类之间可以合作。 * 注意装饰者模式用于给对象添加逻辑以改变原对象的功能而适配器模式用于转换接口 * 以使原对象可以和新接口合作。 * author Bright Lee */ public class AdaptorPattern { public static void main(String[] args) { // 被适配者 Adaptee adaptee new Adaptee(); // 适配器 Adaptor adaptor new Adaptor(adaptee); // 要被适配的接口程序是用这个接口进行工作的 Target target adaptor; target.request(); } } interface Target { public void request(); } /** * 被适配者 */ class Adaptee { public void specificRequest() { System.out.println(我是被适配者。); } } /** * 适配器 */ class Adaptor implements Target { private Adaptee adaptee; public Adaptor(Adaptee adaptee) { this.adaptee adaptee; } public void request() { System.out.println(我是适配器。); adaptee.specificRequest(); } }运行结果我是适配器。我是被适配者。以下是我们工作室开发的软件《榴芒客服系统》的介绍博客里面有软件的下载地址https://blog.csdn.net/look4liming/article/details/164755808
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门