static void Main(string[] args)
        {
            var log = new ConsoleLog();
            var ba  = new BankAccount(log);

            ba.Deposit(100);

            // throws exception
            var ba1 = new BankAccount(null);

            ba1.Deposit(100);

            var nullLog = new NullLog();
            var ba2     = new BankAccount(nullLog);

            ba2.Deposit(100);

            // using ImpromptuInterface
            var log1 = Null <ILog> .Instance;

            log1.Info("asdfasdf");
            var ba3 = new BankAccount(log1);

            ba3.Deposit(100);
        }
        static void Main(string[] args)
        {
            var log = new ConsoleLog();
            var ba  = new BankAccount(log);

            //sta ako ne zelimo log?
            var noLog = new NullLog();
            var ba2   = new BankAccount(noLog);


            //vjezbam dependency injection //nuget autofac

            var cb = new ContainerBuilder();

            cb.RegisterType <BankAccount>();
            cb.RegisterType <NullLog>().As <ILog>();

            using (var c = cb.Build())
            {
                var ba3 = c.Resolve <BankAccount>();
                ba3.Deposit(50);
            }

            //test za dinamicki null objekat
            var nula = Null <ILog> .Instance;
            var ba4  = new BankAccount(nula);

            ba4.Deposit(75);

            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            var log = new NullLog();
            var ba  = new Account(log);

            ba.SomeOperation();
        }
示例#4
0
        private static void Test2()
        {
            var consoleLogger = new NullLog();
            var ba            = new BankAccount(consoleLogger);

            ba.Deposit(50);
        }
示例#5
0
        static void Main(string[] args)
        {
            var consoleLog   = new ConsoleLog();
            var bankAccount1 = new BankAccount(consoleLog);

            bankAccount1.Deposit(100);

            var nullLog      = new NullLog();
            var bankAccount2 = new BankAccount(nullLog);

            bankAccount2.Deposit(150);
        }
        static void Main(string[] args)
        {
            var nullLog = new NullLog();
            var a       = new Account(nullLog);

            a.SomeOperation();
            a.SomeOperation();
            a.SomeOperation();
            a.SomeOperation();
            a.SomeOperation();
            a.SomeOperation();
        }
示例#7
0
        static void Main(string[] args)
        {
            // Real logger
            var log = new ConsoleLog();
            var ba  = new BankAccount(log);

            ba.Deposit(100);
            ba.Withdraw(200);

            // Dummy logger
            var nullLog            = new NullLog();
            var nullLogBankAccount = new BankAccount(nullLog);

            nullLogBankAccount.Deposit(100);

            // Low effort dummy logger (slower, but useful for large interfaces)
            ILog nullTLog            = Null <ILog> .Instance;
            var  nullTLogBankAccount = new BankAccount(nullTLog);

            nullTLogBankAccount.Deposit(100);
        }