static void Main(string[] args)
 {
     var encoder = new VideoEncoder();
     encoder.RegisterNotificationChannel(new MailNotificationChannel());
     encoder.RegisterNotificationChannel(new SmsNotificationChannel());
     encoder.Encode(new Video());
 }
        static void Main(string[] args)
        {
            //reason for using interfaecs:
            //Testability- when we unit testing a class we must isolate it (remove all dependancies to another classes)
            var orderProcessor = new OrderProcessor(new ShippingCalculator()); // this is a dependancy but in the main mthod so i'ts fine.
            var order          = new Order {
                DatePlaced = DateTime.Now, TotalPrice = 100f
            };

            orderProcessor.Process(order);

            //Extensibility - we create new classes insted of changing the code in one class
            var dbMigrator = new DbMigrator(new ConsoleLogger());

            dbMigrator.Migrate();
            var dbMigratoB = new DbMigrator(new FileLogger(@"c:\logging\log.txt"));

            dbMigratoB.Migrate();


            //polymphism:
            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SmsNotificationChannel());
            encoder.Encode(new Video());
        }
Exemple #3
0
        static void Main(string[] args)
        {
            //DbMigrator migrator = new DbMigrator(new Logger());
            //Installer installer = new Installer(new Logger());

            //migrator.Notify();
            //installer.Notify();

            //var orderProcessor = new OrderProcessor(new ShippingCalculator());
            //var order = new Order() {DatePlaced = DateTime.Now, TotalPrice = 100f};
            //orderProcessor.Process(order);


            //var dbMigrator = new DbMigrator(new ConsoleLogger());
            //dbMigrator.Migrate();

            //var dbMigrator2 = new DbMigrator(new FileLogger("C:\\LogMessage\\FileLogger.txt"));
            //dbMigrator2.Migrate();

            var videoEncoder = new VideoEncoder();

            videoEncoder.RegisterNotificationChannel(new MailNotificationChannel());
            videoEncoder.RegisterNotificationChannel(new SmsNotificationChannel());


            videoEncoder.Encode(new Video());
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var orderProcessor = new OrderProcessor(new ShippingCalculator());

            var order = new Order
            {
                DatePlaced = DateTime.Now,
                TotalPrice = 100f
            };

            //orderProcessor.Process(order);


            // In the program, we pass in a concrete implementation of the ILogger interface
            var migrator = new DbMigrator(new ConsoleLogger());

            migrator.Migrate();

            var dbMigrator = new DbMigrator(new FileLogger("C:/Users/cecd304/me/info.txt"));

            dbMigrator.Migrate();

            Console.Clear();

            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SmsNotificationChannel());

            encoder.Encode(new Video());
        }
        static void Main(string[] args)
        {
            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SmsNotificationChannel());
            encoder.Encode(new Video());
        }
Exemple #6
0
        public void InterfacesAndPolymorphism()
        {
            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SmsNotificationChannel());
            encoder.Encode(new Video());
        }
Exemple #7
0
        public static void Demo()
        {
            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SmsNotificationChannel());
            encoder.Encode(new Video());
        }
Exemple #8
0
        static void UsePolymorphism()
        {
            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SMSNotificationChannel());
            encoder.Encode(new Video());
        }
Exemple #9
0
        static void Interfaces()
        {
            // Interfaces and Testability
            // var orderProcessor = new OrderProcessor(new ShippingCalculator());
            // var order = new Interfaces.Order { DatePlaced = DateTime.Now, TotalPrice = 100f };
            // orderProcessor.Process(order);


            // Interfaces and Extensibility
            // var dbMigrator = new Interfaces.DbMigrator(new ConsoleLogger());
            // dbMigrator.Migrate();
            // var dbMigrator2 = new Interfaces.DbMigrator(new FileLogger("/Users/itabarino/Downloads/log.txt"));
            // dbMigrator2.Migrate();


            // Interfaces are NOT for Multiple Inheritance
            // One of the common misconceptions about interfaces is that they are used to implement multiple inheritance in C#.
            // This is fundamentally wrong, yet many books and videos make such a false claim.
            // With inheritance, we write code once and re-use it without the need to type all that code again.
            // With interfaces, we simply declare the members the implementing class should contain.
            // Then we need to type all that declaration along with the actual implementation in that class.
            // So, code is not inherited, even the declaration of the members!
            // In Inheritance you write all the code in the parent class
            // and all derived classes inherit all the code from the parent class
            // The Interfaces don't have any code, just includes the method declaration
            // So, there is not code to inherit
            // A class implements an Multiple Interface and extends from only one class.
            // Check the code in the TextBox to see that extends from UiControl and implements IDraggable and IDroppable
            // var textBox = new TextBox();
            // textBox.Focus();


            // Interfaces and Polymorphism
            // OCP - software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
            // We implemented the OCP (Open-Closed Principle) here.
            var encoder = new VideoEncoder();

            encoder.RegisterNotificationChannel(new MailNotificationChannel());
            encoder.RegisterNotificationChannel(new SmsNotificationChannel());
            encoder.Encode(new Video());
        }