Add all 23 GoF design pattern implementations (2026-06-13)
This commit is contained in:
39
02-structural/facade/VideoConversionFacade.java
Normal file
39
02-structural/facade/VideoConversionFacade.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package facade;
|
||||
|
||||
/**
|
||||
* Facade — the single, simple entry point to a complex video subsystem.
|
||||
*
|
||||
* Without this class, clients need to know about CodecFactory,
|
||||
* BitrateReader, AudioMixer, and VideoFile — 4 classes, dozens of methods.
|
||||
* The facade reduces that to ONE method call.
|
||||
*
|
||||
* The subsystem classes still exist and can be used directly
|
||||
* by advanced users who need fine-grained control.
|
||||
*/
|
||||
public class VideoConversionFacade {
|
||||
|
||||
public String convertVideo(String inputFile, String targetFormat) {
|
||||
System.out.println("VideoConversionFacade: starting conversion of " + inputFile);
|
||||
|
||||
// Step 1: open the file and detect codec
|
||||
VideoFile file = new VideoFile(inputFile);
|
||||
Codec sourceCodec = CodecFactory.extract(file);
|
||||
|
||||
// Step 2: prepare destination codec
|
||||
Codec destCodec;
|
||||
if ("mp4".equals(targetFormat)) {
|
||||
destCodec = new MPEG4CompressionCodec();
|
||||
} else {
|
||||
destCodec = new OggCompressionCodec();
|
||||
}
|
||||
|
||||
// Step 3: read, mix audio, encode
|
||||
VideoFile buffer = BitrateReader.read(file, sourceCodec);
|
||||
VideoFile intermediateResult = BitrateReader.convert(buffer, destCodec);
|
||||
VideoFile result = AudioMixer.fix(intermediateResult);
|
||||
|
||||
String outputFilename = inputFile.replaceAll("\\.[^.]+$", "." + targetFormat);
|
||||
System.out.println("VideoConversionFacade: conversion complete -> " + outputFilename);
|
||||
return outputFilename;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user