Prism
Newcomer
What is it?
The Facade design pattern is a commonly used pattern which pretty much every programming language API uses for general usage. In this design pattern, you use a single class to hide the details of a complex object, or even a set of classes. For example, java.net.InetAddress, its purpose is to connect to a specific URL and retrieve information about the host, etc. however it hides all of the complex detail (ex. using DNS to get the IP address of a host).
Simple example from Wikipedia:
If you have any questions, feel free to ask me!
The Facade design pattern is a commonly used pattern which pretty much every programming language API uses for general usage. In this design pattern, you use a single class to hide the details of a complex object, or even a set of classes. For example, java.net.InetAddress, its purpose is to connect to a specific URL and retrieve information about the host, etc. however it hides all of the complex detail (ex. using DNS to get the IP address of a host).
Simple example from Wikipedia:
Code:
/* Complex parts */
class CPU {
public void freeze() { ... }
public void jump(long position) { ... }
public void execute() { ... }
}
class Memory {
public void load(long position, byte[] data) { ... }
}
class HardDrive {
public byte[] read(long lba, int size) { ... }
}
/* Facade */
class ComputerFacade {
private CPU processor;
private Memory ram;
private HardDrive hd;
public ComputerFacade() {
this.processor = new CPU();
this.ram = new Memory();
this.hd = new HardDrive();
}
public void start() {
processor.freeze();
ram.load(BOOT_ADDRESS, hd.read(BOOT_SECTOR, SECTOR_SIZE));
processor.jump(BOOT_ADDRESS);
processor.execute();
}
}
/* Client */
class You {
public static void main(String[] args) {
ComputerFacade computer = new ComputerFacade();
computer.start();
}
}
If you have any questions, feel free to ask me!
