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