03.结构型设计模式实验

本文探讨了结构型设计模式的实验,包括对象适配器、类适配器、桥接模式、组合模式、装饰模式、享元模式和代理模式。通过类图和代码示例展示了各个模式的实现,特别提到了代理模式在缓存策略中的应用。
摘要由CSDN通过智能技术生成

结构型设计模式实验

写在前面

由于我懒,没有继续写运行结果,也没有再贴原题目,同时源代码,,,说来惭愧,我也是抄的,由于没有实际验证,我无法保证。等寒假我好好整理一波吧!如果我还想得起来。。。

对象适配器:

类图:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8H9T3FF3-1638275767876)(03.结构型设计模式实验/image-20211110212133850.png)]

代码:

public class Encrypt{
   
	String encodeInformation(String inf);
}
public class Adaptee{
   
	public String encodeAlgorithm(String inf) {
   
	String serect="*";
	for (int i=0; i<=inf.length();i++) {
   
		serect+="*";
	}
	serect+="\n";
	serect+="*"+inf+"*"+"\n";
	serect+=serect.substring(0, inf.length()+2);
	return serect;
	}
}
class Adapter extends  Encrypt{
   
	Adaptee adaptee;
}

类适配器:

类图:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hwHqxOOm-1638275767878)(03.结构型设计模式实验/image-20211110214727829.png)]

interface Encrypt{
   
	String encodeInformation(String inf);
}
public class Adaptee{
   
	public String encodeAlgorithm(String inf) {
   
	String serect="*";
	for (int i=0; i<=inf.length();i++) {
   
		serect+="*";
	}
	serect+="\n";
	serect+="*"+inf+"*"+"\n";
	serect+=serect.substring(0, inf.length()+2);
	return serect;
	}
}
class Adapter extends  Adaptee implenments Encrypt{
   
    public String encodeInformation(String inf) {
   
	System.out.println("加密"+inf);
	return encodeAlgorithm(inf);
	}
}

桥接模式:

类图:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XDpYVg8d-1638275767879)(03.结构型设计模式实验/image-20211110213355335.png)]

代码:

public class photoApp {
   
	protected Filter filter;
	protected String photo;
	public void applyfilter() {
   
	filter.processPhoto(photo);
	}
}
class GIF extends photoApp{
   
	public GIFphoto(Filter filter) {
   
	this.filter = filter;
	}
	public void openGIF(String p) {
   
	this.photo=p;
	}
}
class JPG extends photoApp{
   
	public JPGphoto(Filter filter) {
   
	this
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值