Beispiel #1
0
        protected void Promote()
        {
            // It's not a good practice to instanciate a object inside of a method
            // Because this creates coupling or dependency of this object
            var calculator = new RateCalculator();
            var rating     = calculator.Calculate(this);

            if (rating == 10)
            {
                Console.WriteLine("Promoted to Level 1");
            }
            else
            {
                Console.WriteLine("Promoted to Level 2");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var customer = new Customer();

            customer.Id   = 1;
            customer.Name = "Helmut";
            Amazon.RateCalculator calculator = new RateCalculator();

            var car = new Car("BL1258");

            // downcasting and upcasting
            Text  text  = new Text();
            Shape shape = text;

            text.Width  = 200;
            shape.Width = 100;

            System.Console.WriteLine(text.Width);

            Shape shapeDown = new Text();
            Text  textDown  = (Text)shape;
        }