package com.jmj.pattern.bridge;
/**
* 视频文件(实现化角色)
*/
public interface VideoFile {
void decode(String fileName);
}
package com.jmj.pattern.bridge;
public class RmvFile implements VideoFile{
@Override
public void decode(String fileName) {
System.out.println("rmvb视频文件:"+fileName);
}
}
package com.jmj.pattern.bridge;
/**
* avi视频文件(具体的实现化角色)
*/
public class AviFile implements VideoFile{
@Override
public void decode(String fileName) {
System.out.println("avi 视频文件 : "+fileName);
}
}
package com.jmj.pattern.bridge;
public abstract class OpratingSystem {
//声明videoFile变量
protected VideoFile videoFile;
public OpratingSystem(VideoFile videoFile) {
this.videoFile = videoFile;
}
public abstract void play(String fileName);
}
package com.jmj.pattern.bridge;
/**
* 扩展抽象化角色(windows操作系统)
*/
public class Windows extends OpratingSystem{
public Windows(VideoFile videoFile) {
super(videoFile);
}
@Override
public void play(String fileName) {
videoFile.decode(fileName);
}
}
package com.jmj.pattern.bridge;
public class Mac extends OpratingSystem{
public Mac(VideoFile videoFile) {
super(videoFile);
}
@Override
public void play(String fileName) {
videoFile.decode(fileName);
}
}
package com.jmj.pattern.bridge;
public class Client {
public static void main(String[] args) {
//创建mac系统对象
OpratingSystem system=new Mac(new RmvFile());
system.play("战狼3");
}
}