![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
AI 开发者
支付宝软件工程师
展开
-
设计模式 by Java——简单工厂模式
一个简单的例子,模拟应用程序中调取支付接口。支付接口public interface Payment { void pay(double price);}微信支付类,实现支付接口public class WechatPayment implements Payment { @Override public void pay(double price) { System.out.println("通过微信支付" + price + "元."); }原创 2020-07-30 12:42:58 · 227 阅读 · 0 评论 -
设计模式 by Java——适配器模式
一个简单的例子,模拟电脑插入电源插座。假设中国电脑额定电压为220V,美国电脑额定电压为110V,中国家用交流电电压220V。1.不使用适配器的情况电源插座类public class Socket { private final int VOLTAGE = 220; public int getVOLTAGE() { return this.VOLTAGE; }}电脑类public abstract class Computer { publ原创 2020-07-30 12:31:35 · 199 阅读 · 0 评论