package com.eric.设计模式原则.接口隔离原则;
/**
* @author Eric
* @ProjectName my_design_23
* @description 用户门户与订单的接口
* @CreateTime 2020-11-23 17:55:02
*/
//用户门户应用接口
public interface IOrderForPortal {
public String getOrder();
}
package com.eric.设计模式原则.接口隔离原则;
/**
* @author Eric
* @ProjectName my_design_23
* @description 外部系统与订单接口
* @CreateTime 2020-11-23 17:56:20
*/
//外部系统应用接口
public interface IOrderForOtherSys {
public void insertOrder();
}
package com.eric.设计模式原则.接口隔离原则;
/**
* @author Eric
* @ProjectName my_design_23
* @description 管理平台和订单的接口
* @CreateTime 2020-11-23 17:56:56
*/
//管理平台应用接口
public interface IOrderForAdmin {
public String getOrder();
public void insertOrder();
public void updateOrder();
public void deleteOrder();
}
package com.eric.设计模式原则.接口隔离原则;
/**
* @author Eric
* @ProjectName my_design_23
* @description 订单类
* @CreateTime 2020-11-23 17:58:56
*/
public class Order implements IOrderForAdmin,IOrderForOtherSys,IOrderForPortal {
//返回给Portal
public static IOrderForPortal getOrderForPortal(){
return new Order();
}
//返回给OtherSys
public static IOrderForOtherSys getOrderForOtherSys(){
return new Order();
}
//返回给Admin
public static IOrderForAdmin getOrderForAdmin(){
return new Order();
}
public String getOrder() {
return "返回订单";
}
public void insertOrder() {
System.out.println("插入订单");
}
public void updateOrder() {
System.out.println("更新订单");
}
public void deleteOrder() {
System.out.println("删除订单");
}
}
package com.eric.设计模式原则.接口隔离原则;
/**
* @author Eric
* @ProjectName my_design_23
* @description 某电子商务系统业务的测试类
* @CreateTime 2020-11-23 18:10:10
*/
public class test {
public static void main(String[] args) {
//获取用户门户对应的实例,该对象只能使用getOrder()方法
IOrderForPortal op = Order.getOrderForPortal();
System.out.println(op.getOrder());
//获取外部系统接口对应的实例,该对象只能用insertOrder()方法
IOrderForOtherSys os = Order.getOrderForOtherSys();
os.insertOrder();
//获取管理平台接口对应的实例,该对象可以使用Order类中提供的所有方法
IOrderForAdmin oa = Order.getOrderForAdmin();
System.out.println(oa.getOrder());
oa.insertOrder();
oa.updateOrder();
oa.deleteOrder();
}
}
原文:https://www.cnblogs.com/zyl-0110/p/14027173.html