=== pedro_ is now known as pedro3005 === Mike is now known as Guest9272 === bgs100 is now known as bgs000 === bgs000 is now known as bgs100 === daker_ is now known as daker === DarkwingDuck_ is now known as DarkwingDuck === maco2 is now known as maco === emma_ is now known as emma === jarlen_ is now known as jarlen === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Current Session: Introduction to C#: Session 4 - Instructor: juju2143 || Questions in #ubuntu-classroom-chat [21:02] juju2143: you about? [21:05] hopefully he just got tied up elsewhere and will arrive soon :) [21:12] ohhhh right [21:12] the course. [21:12] everyone's there? [21:13] yep [21:13] I'm ready (; [21:14] hello juju2143 and pleia2 [21:14] \o [21:14] hello. [21:15] so last Friday, we did classes === yofel_ is now known as yofel [21:16] now we'll do inheritance. [21:16] It's one of the advanced features of OOP [21:19] So, like our last example, we created a Person class [21:20] hmm.. I think I've lost it... could You paste it to some nopaste? [21:20] say you are programming some RPG game, you would like a Warrior or a magician [21:20] So you could create a warrior class and a Magician class [21:22] These classes would be exactly the same, with the exceptions of some methods such as doMagic(), or mana level [21:24] So why not put these methods and attributes in common in the same class? [21:24] I would compare it to the apt-get system of Ubuntu [21:24] like, Warrior and Magician both depends on libperson === Pendulum_ is now known as Pendulum [21:25] same thing in C# and in every OOP language that supports inheritance [21:26] the warrior class would include the Person class and take its attributes, etc. [21:27] so open your console application. [21:28] in Main.cs you would have something like this: [21:28] Class Person [21:28] { [21:28] ... [21:28] } [21:29] Class Warrior : Person [21:29] { [21:29] ... [21:29] } [21:29] class Magician : Person [21:29] { [21:29] ... [21:29] } [21:29] (right, the C in class should be lowercased) [21:30] So it's really simple. [21:30] You add this : Person thing [21:31] and you can add methods in Warrior like if you were in Person [21:31] same thing in Magician, but without the methods in Warrior. [21:32] sirmacik, they are not needed, just have a console application handy. And paste the classes in there. [21:33] so if you have this: [21:33] class Person [21:33] { [21:34] public Person(string Sex) [21:34] { [21:34] m_sex = sex; [21:34] } [21:34] public string m_sex = "Male"; [21:34] } [21:35] so in your Main() you can instanciate Person like this: [21:35] Person a = new Person("Male"); [21:36] you should, even there is nothing in Warrior, instanciate it like Person, just replace Person with Warrior [21:38] So, that's it for inheritance. [21:38] :o [21:38] nice (; [21:39] Now there something else worth mentioning today. [21:39] (damn I forgot what it's called) [21:39] So you can have methods of the same name in same class [21:40] Only difference is the type of return and/or number of arguments. [21:42] (hm, finally, disregard the type of return, the compiler have no way to know which type to return) [21:43] So, say you have a method called doSomething. [21:44] You can have a dosomething that takes no arguments, one that takes a string, one that takes an int, one that takes one string and one int, etc. [21:45] So you could have endless methods with the same name. [21:47] Also, something interesting with inheritenceyou can do is polymorphism. [21:48] Now you are wondering what's this big word. [21:48] Something you should know is that all classes inherits from System.Object [21:50] something you can do is simply put your Person class in an object [21:50] juju2143, sorry [21:51] like this: object o = a [21:51] pedro3005, oh no problem [21:52] so it's kinda useful if you have a method, say doSomething, who takes an argument you don't know what ii is [21:52] it* [21:53] public void doSomething(object o) [21:53] { [21:54] // do something with o, who would be anything [21:54] } [21:54] and then could you test upon the type? like if (isint) or something? [21:54] yeah, something like that [21:55] then you can give doSomething a Person or a string [21:56] same thing if you replace object by Person in the above example [21:56] you could give a Warrior or a Magician to your method [21:58] So you transformed your Person into an object [21:58] now to do the inverse you could write this: [21:58] Person p = (Person)o [21:58] (you need to cast it) [21:59] so you'd be transforming o into a person object? [21:59] yep [21:59] but that's weird [21:59] this is encapsulation. [21:59] what is o? [22:00] can you transform anything into a person object? [22:00] o is an object containing a Person [22:00] so: [22:00] Person a = new Person("Male"); [22:00] object o = a; [22:01] Person p = (Person)o [22:01] ; [22:01] like you could do this: [22:02] double a_double = (double)an_integer; [22:02] where an_integer is an int variable [22:04] this is casting (and not castration) [22:06] oh yeah, for the thing with methods of the same name [22:06] it doesn't work well with constructors [22:07] so you have to do this: [22:07] public Person(string arg) : this() [22:07] { [22:07] } [22:08] in fact it works without this() (i think) [22:08] but there you can reuse the constructor without arguments in the constructor with arguments [22:09] so this won't work: [22:09] public Person(string args) [22:09] { [22:09] Person(); // or this(); [22:09] } [22:09] it would give an error. [22:11] So I think that's it for today for inheritence and that thing I forgot the name [22:11] for today [22:11] homework: mess with these things [22:11] are there going to be next lessons? [22:12] i don't know, I think so [22:12] come back tomorrow, we'll see. Maybe we'll do graphics. [22:13] oh, that'd be great (; [22:13] yep :P [22:14] see You then, good night [22:14] (it's 23:14 here) [22:16] good night. [22:16] :P [22:18] alright juju2143, thanks for the lesson [22:20] your welcome. [22:22] There are are 10 minutes remaining in the current session. [22:22] adding next one to the calendar [22:25] There are are 5 minutes remaining in the current session. === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi