https://refactoring.guru/design-patterns/proxy
Proxy
There are dozens of ways to utilize the Proxy pattern. Let’s go over the most popular uses. Access control (protection proxy). This is when you want only specific clients to be able to use the service object; for instance, when your objects are crucial p
refactoring.guru
특정 객체를 wrapping해서 일종의 대리 처럼 사용하며, 그 과정에서 추가적인 기능을 구현할때.
=> 로깅, 캐싱, deferred loading, 보안 등의 기능 추가.

예시
- 로그 추가용 proxy
- 접근 제어용 proxy
- 리모트 데이터 캐싱용 proxy
- Deferred load 용 proxy 등.
예제 코드
더보기
class BundleLoader
{
public void Load() { }
}
class BundleLoaderProxy
{
BundleLoader _bundleLoader;
public void Load()
{
if(_bundleLoader == null ) // delayed loading.
_bundleLoader = new BundleLoader();
// ADD LOGS
_bundleLoader.Load();
// ADD LOGS
}
}
internal class ProxyDemo
{
public void Run()
{
BundleLoaderProxy proxy = new BundleLoaderProxy();
proxy.Load();
}
}
}
'Work & Programming > System Design' 카테고리의 다른 글
[Behavioral Pattern] - Command (0) | 2024.05.16 |
---|---|
[Behavioral Pattern] - Chain Of Responsibility (0) | 2024.05.16 |
[Structural Pattern] - Flyweight (0) | 2024.05.15 |
[Structural Pattern] - Facade (0) | 2024.05.15 |
[Structural Pattern] - Decorator (0) | 2024.05.15 |