Work & Programming/System Design

[Structural Pattern] - Flyweight

자전거통학 2024. 5. 15. 10:35

https://refactoring.guru/design-patterns/flyweight

 

Flyweight

/ Design Patterns / Structural Patterns Flyweight Also known as: Cache Intent Flyweight is a structural design pattern that lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keep

refactoring.guru

 

자원의 효율적 사용을 위해 특정 키를 부여하고 이 키를 통해 자원을 캐싱 하고자 할때.

 

예시 

 - TextureCacheManager

 - AssetManager

 

예제 코드 

더보기
class BundleLoader
{
    public void Load() { }
}

 class AssetBundle
{

}
class AssetBundleMng
{
    Dictionary<string, AssetBundle> _dictBundles;

    AssetBundle GetBundle(string name)
    {
        return _dictBundles[name];
    }
}

internal class FlightWeight
{
}