桥接模式之消息发送

1、 实例概况

电子商务网站常有这样的功能:发送消息通知,比如订货发货通知等,从业务上看,消息分为普通消息、加急消息和特急消息多种不同的消息类型,其业务处理是不一样的,比如加急消息是在消息上添加加急标记,而特急消息是添加了加急标记外,还会做一条催促的记录,多久不完成会继续催促。从发送消息的手段上看,又有系统内消息、手机短信消息、邮件等。请使用合适的设计模式进行设计,绘制所选择模式的结构图,并绘制该案例的类图,并编写代码实现并进行演示。

2、所用模式结构视图

桥接模式结构视图

3、实例类图

桥接模式实例类图

4、实例实现代码

4.1实现类接口ZC32Type(消息类型类)

public interface ZC32Type {
	
	void besend(String MeansType,String counts);
}

4.11具体实现类ZC32CommonNews(普通消息类)

public class ZC32CommonNews implements ZC32Type{
	public void besend(String MeansType,String counts) {
		System.out.println( MeansType+"普通消息"+counts+".");
	}
}

4.12具体实现类ZC32UNews(加急消息类)

public class ZC32UNews implements ZC32Type{
	public void besend(String MeansType,String counts) {
		System.out.println( MeansType+"加急消息"+counts+".");
	}
}

4.13具体实现类ZC32EuNews(特急消息类)

public class ZC32EuNews implements ZC32Type{
	public void besend(String MeansType,String counts) {
		System.out.println( MeansType+"特急消息"+counts+".");
	}
}

4.2抽象类ZC32Means(发送消息手段类)

public abstract class ZC32Means {
	protected ZC32Type type;
	public void setType(ZC32Type type) {
		this.type=type;
	}
	public abstract void send(String counts);
}

4.21扩充抽象类ZC32SystemNews(系统内消息类)

public class ZC32SystemNews extends ZC32Means{
	public void send(String counts)
	{
		String MeansType="系统内消息";
		this.type.besend(MeansType, counts);
	}
}

4.22扩充抽象类ZC32PhoneNews(手机短信消息类)

public class ZC32PhoneNews extends ZC32Means{
	public void send(String counts)
	{
		String MeansType="手机短信消息";
		this.type.besend(MeansType, counts);
	}
}

4.23扩充抽象类ZC32MailNews(邮件消息类)

public class ZC32MailNews extends ZC32Means{
	public void send(String counts)
	{
		String MeansType="邮件消息";
		this.type.besend(MeansType, counts);
	}

}

4.3客户端测试类ZC32Client

public class ZC32Client {
	public static void main(String args[]) {
		ZC32Type type1 =new ZC32EuNews();
		ZC32Means means1=new ZC32MailNews();
		means1.setType(type1);
		means1.send("一条");
	
		ZC32Type type2 =new ZC32UNews();
		ZC32Means means2=new ZC32PhoneNews();
		means2.setType(type2);
		means2.send("五条");
	
		ZC32Type type3 =new ZC32CommonNews();
		ZC32Means means3=new ZC32SystemNews();
		means3.setType(type3);
		means3.send("八条");	
	}
}

5、结果

桥接模式结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我超(菜鸡版)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值