facade
Provide a simplified interface to a complex subsystem.
SKILL.mdskills/code-quality/facade/SKILL.md
GitHubFacade
Provides a single, simplified interface that hides the complexity of a subsystem. Clients use the facade instead of the many subsystem classes directly.
When to Use
- A subsystem has many classes with complex interactions
- You want to layer your architecture (facade = entry point to a layer)
- Integration with a complex library or framework should be encapsulated
- You need a simple default use case while keeping the subsystem accessible for advanced use
How to Apply
- Check whether a simpler interface is possible and valuable
- Declare and implement the
Facadeclass, delegating to subsystem classes - Clients call the facade instead of directly accessing subsystem classes
- Keep subsystem classes accessible for clients that need fine-grained control
Example
// Complex subsystem
class VideoDecoder { decode(file: string) { /* … */ } }
class AudioMixer { fix(audio: string) { /* … */ } }
class BitrateReader { read(file: string) { return 1080; } }
// Facade
class VideoConverter {
private decoder = new VideoDecoder();
private mixer = new AudioMixer();
private reader = new BitrateReader();
convert(filename: string, format: string): string {
const bitrate = this.reader.read(filename);
this.decoder.decode(filename);
this.mixer.fix(filename);
return `output.${format}`;
}
}
// Client only needs one call
const converter = new VideoConverter();
const output = converter.convert('funny-cats.ogg', 'mp4');