public static void Questions() { // class Person { } Person me = new Person(); Person you = new Person(); //Q. how many people are there? //... ie. how many values (object) of the type Person are there? //A. 2 // class Detective : Person {} Detective holmes = new Detective(); Detective marple = new Detective(); //Q. how may people are there? //A. 4 System.Console.WriteLine(holmes is Detective); System.Console.WriteLine(me is Detective); System.Console.WriteLine(holmes is Person); System.Console.WriteLine(holmes.GetType().Name); }
public static void Relationships() { Person me = new Person(); Person you = new Person(); /* * me and you belong to the class Person * the type 'Person' denotes the set {me, you} * 'new Person' adds an element (a person) to the set * * cf. bool means {true, false}, int means {-2^32, ..., 0, ..., 2^32 - 1} */ Detective sherlock = new Detective(); Doctor watson = new Doctor(); System.Console.WriteLine(sherlock is Person); System.Console.WriteLine(sherlock is Detective); System.Console.WriteLine(watson is Person); System.Console.WriteLine(watson is Doctor); // 'is' expression's given expression is never of the provided type System.Console.WriteLine(watson is Detective); // 'is' expression's given expression is never of the provided type //c. objects however have one 'cannonical' type, the type they were made from //ie., the type new'd -- even though they belong to multiple System.Console.WriteLine(sherlock.GetType().Name); System.Console.WriteLine(watson.GetType().Name); //d. there are two ways of saying an object belongs to multiple types //1. if the supertype is an interface = implementation //2. if the sypertype is a class = inheritance //NB. supertype is the larger group, ie. the type on the RHS of : // SubType : SuperType //let's stop here on the syntax/demos and talk about the concepts... //syntax revisited / continued }