Add all 23 GoF design pattern implementations (2026-06-13)
This commit is contained in:
62
02-structural/facade/Subsystems.java
Normal file
62
02-structural/facade/Subsystems.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package facade;
|
||||
|
||||
/**
|
||||
* Complex subsystem classes — these are what the Facade hides.
|
||||
* Each class has its own complex API; clients shouldn't need to know all of them.
|
||||
*/
|
||||
|
||||
class VideoFile {
|
||||
private final String filename;
|
||||
private final String codecType;
|
||||
|
||||
VideoFile(String filename) {
|
||||
this(filename, filename.endsWith(".mp4") ? "mpeg4" : "ogg");
|
||||
}
|
||||
|
||||
VideoFile(String filename, String codec) {
|
||||
this.filename = filename;
|
||||
this.codecType = codec;
|
||||
System.out.println(" VideoFile: " + filename + " [codec: " + codecType + "]");
|
||||
}
|
||||
|
||||
public String getFilename() { return filename; }
|
||||
public String getCodecType() { return codecType; }
|
||||
}
|
||||
|
||||
interface Codec { String getName(); }
|
||||
|
||||
class MPEG4CompressionCodec implements Codec {
|
||||
@Override public String getName() { return "mpeg4"; }
|
||||
}
|
||||
|
||||
class OggCompressionCodec implements Codec {
|
||||
@Override public String getName() { return "ogg"; }
|
||||
}
|
||||
|
||||
class CodecFactory {
|
||||
static Codec extract(VideoFile file) {
|
||||
System.out.println(" CodecFactory: extracting codec from " + file.getFilename());
|
||||
if ("mpeg4".equals(file.getCodecType())) return new MPEG4CompressionCodec();
|
||||
return new OggCompressionCodec();
|
||||
}
|
||||
}
|
||||
|
||||
class BitrateReader {
|
||||
static VideoFile read(VideoFile file, Codec codec) {
|
||||
System.out.println(" BitrateReader: reading " + file.getFilename()
|
||||
+ " with codec " + codec.getName());
|
||||
return new VideoFile(file.getFilename());
|
||||
}
|
||||
|
||||
static VideoFile convert(VideoFile buffer, Codec codec) {
|
||||
System.out.println(" BitrateReader: converting to " + codec.getName());
|
||||
return new VideoFile(buffer.getFilename());
|
||||
}
|
||||
}
|
||||
|
||||
class AudioMixer {
|
||||
static VideoFile fix(VideoFile result) {
|
||||
System.out.println(" AudioMixer: fixing audio tracks");
|
||||
return new VideoFile(result.getFilename());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user