プロキシパターンは、別のオブジェクトに対してプレースホルダーまたは代理を提供し、そこへのアクセスを制御します。プロキシは実オブジェクトと同じインターフェースを持ちますが、遅延ローディング、アクセス制御、キャッシング、ロギングなどの動作を追加した後、実オブジェクトに委譲します。
プロキシパターンがすること
PROXY → an object that STANDS IN for another, controlling access to it:
→ same interface as the real object (clients use it transparently)
→ adds behavior BEFORE/AROUND delegating to the real object
→ controls WHEN and HOW the real object is accessed
→ "a stand-in that adds control/behavior"
プロキシの種類
VIRTUAL proxy → LAZY initialization → create/load the real object only when needed
(e.g. defer loading a heavy resource until first use)
PROTECTION proxy → ACCESS CONTROL → check permissions before allowing access
CACHING proxy → cache results → return cached data instead of re-fetching/recomputing
REMOTE proxy → represent an object in another location (network/remote calls hidden)
LOGGING/smart proxy → add logging, reference counting, etc. around access
