Exemple #1
0
    void TestFlyWeight()
    {
        FlyweightFactory factory = new FlyweightFactory();

        FlyWeight flyWeightX = factory.GetFlyweight("酷炫效果");

        flyWeightX.Operation();

        FlyWeight flyWeightY = factory.GetFlyweight("旋转效果");

        flyWeightY.Operation();

        FlyWeight flyWeightZ = factory.GetFlyweight("光影效果");

        flyWeightZ.Operation();

        FlyWeight flyWeightUnshared = new UnsharedConcreteFlyWeight("火焰效果");

        flyWeightUnshared.Operation();

        FlyWeight flyWeightM = factory.GetFlyweight("光影效果");

        flyWeightM.Operation();

        FlyWeight flyWeightN = factory.GetFlyweight("光影效果");

        flyWeightN.Operation();

        Debug.Log("Total number of fly weight : " + factory.GetFlyWeightCount());
    }
Exemple #2
0
        static void Main(string[] args)
        {
            int extrinsicstate = 22;

            FlyWeightFactory flyWeightFactory = new FlyWeightFactory();

            FlyWeight flyWeightX = flyWeightFactory.GetFlyWeight("X");

            flyWeightX.Operation(--extrinsicstate);

            FlyWeight flyWeightY = flyWeightFactory.GetFlyWeight("Y");

            flyWeightY.Operation(--extrinsicstate);

            FlyWeight flyWeightZ = flyWeightFactory.GetFlyWeight("Z");

            flyWeightZ.Operation(--extrinsicstate);

            FlyWeight uf = new UnsharedConcreteFlyWeight();

            uf.Operation(--extrinsicstate);
        }