static void Main(string[] args)
        {
            var simpleFactory = new ObjectFactory();

            WriteLine(
                $"Is {nameof(simpleFactory)} a singleton? It is {SingletonTester.IsSingleton(simpleFactory.Create)}.");
            var singletonFactory = new SingletonObjectFactory();

            WriteLine($"Is {nameof(singletonFactory)} a singleton? If is {SingletonTester.IsSingleton(singletonFactory.Create)}");
        }
Beispiel #2
0
        protected override void OnInitialize()
        {
            base.OnInitialize();
            Initialization();
            DelegateSubscribe();
            buttonOneClick += (str) =>
            {
                Debug.Log("!!! " + str);
                var cd = new SingletonObjectFactory().AcquireObject(typeof(CustomTestData).FullName) as CustomTestData;
                cd.A = 1;
                cd.B = "1111111111111111";
                Debug.Log(cd);

                var cd2 = new TransientObjectFactory().AcquireObject(typeof(CustomTestData).FullName) as CustomTestData;
                cd2.A = 2;
                cd2.B = "2222222222222222";
                Debug.Log(cd2);

                var cd3 = PoolObjectFactory.Instance.AcquireObject(typeof(CustomTestData).FullName) as CustomTestData;
                cd3.A = 3;
                cd3.B = "3333333333333333";
                Debug.Log(cd3);

                var cd4 = ComponentFactory.Instance.Create <TestComponentClass>(typeof(TestComponentClass).FullName) as TestComponentClass;
                cd4.A = 4;
                cd4.B = "4444444444444444";
                Debug.Log(cd4.InstanceId);

                ObjectPool.Instance.Recycle(cd4, typeof(TestComponentClass).FullName);

                var cd5 = ComponentFactory.Instance.Create <TestComponentClass>(typeof(TestComponentClass).FullName) as TestComponentClass;
                cd5.A = 5;
                cd5.B = "5555555555555555";
                Debug.Log(cd5.InstanceId);
            };
        }