[Refactoring Guru: Facade](https://refactoring.guru/design-patterns/facade)
Notes: [[Design Pattern/Notes/structural/facade|facade]]
Facade is nothing special, all libraries are essentially using #facade-design-pattern .
For example, in Kunkun's API package `@kksh/api`, I expose a function for Deno to expose functions for the main extension process to call.
See [code](https://github.com/kunkunsh/kunkun/blob/bf51fdadbc2227a5ba9e42903698f143b56facc1/packages/api/src/runtime/deno.ts#L4)
[This is how it's used.](https://github.com/kunkunsh/kunkun/blob/bf51fdadbc2227a5ba9e42903698f143b56facc1/packages/extensions/demo-worker-template-ext/deno-src/rpc.ts#L40)
```ts
import { expose } from "@kksh/api/runtime/deno"
expose(apiMethods)
```
While in the background, it does some extra work, like creating Deno stdio and setting up the bidirectional channel.
```ts
import { DenoIo, RPCChannel } from "kkrpc"
// deno-lint-ignore no-explicit-any
export function expose(api: Record<string, any>) {
const stdio = new DenoIo(Deno.stdin.readable)
const channel = new RPCChannel(stdio, { expose: api })
return channel
}
export { DenoIo, RPCChannel } from "kkrpc"
```
The library acts as a facade, hiding logic behind the scenes, and let user deal with a single, simple `expose()` function.