结构型设计模式实验
写在前面
由于我懒,没有继续写运行结果,也没有再贴原题目,同时源代码,,,说来惭愧,我也是抄的,由于没有实际验证,我无法保证。等寒假我好好整理一波吧!如果我还想得起来。。。
对象适配器:
类图:
代码:
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;
}
类适配器:
类图:
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);
}
}
桥接模式:
类图:
代码:
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