Exemplo n.º 1
0
        // END INTERLUDE...


        public static void Objects()
        {
            //4. The foundations of imperative programming (OO)

            /*
             *           We need to go back to state, behaviour, identity and type
             *           and clarify what each now mean as applied to *objects*
             *                   (...which are not merely simple values).
             *
             */

            //sherlock is the object, Detective its type
            Detective sherlock = new Detective
            {     //NB. we can set the state of the object when we create it
                name   = "Sherlock Holmes",
                height = 1.81,
                weight = 70
            };

            //what is its state?

            System.Console.WriteLine(sherlock.name);
            System.Console.WriteLine(sherlock.height);
            System.Console.WriteLine(sherlock.weight);

            //how does it's state change?

            sherlock.Eat(0.5); //sherlock increases its own weight


            //what is its behaviour?
            // its methods, eg. sherlock.Eat


            //identity?
            var me  = sherlock;
            var you = sherlock;


            System.Console.WriteLine(me == you);


            System.Console.WriteLine(sherlock == new Detective
            {
                name = "Sherlock Holmes"
            });

            // sherlock == someone else called sherlock ? NOPE



            /*
             *           for simple data values identity and equality are the same
             *           for objects these come apart
             *
             *           conditions underwhich we might want to say two objects are "equal"
             *           (eg. equal in price) do not imply the objects are the same
             *
             *           your house might be "equal-to" a £300,000 check
             *           but I cannot demolish your house and replace it with a piece of paper
             *
             *           identity means (according to Leibniz at least) equal in every possible way
             *
             *           For x to identitical to y is for x to be y
             *           For Michael to be identiical to Mike is for Michael and Mike to refer to exactly the same object.
             */
        }