=== 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
pleia2juju2143: you about?21:02
pleia2hopefully he just got tied up elsewhere and will arrive soon :)21:05
juju2143ohhhh right21:12
juju2143the course.21:12
juju2143everyone's there?21:12
sirmacikI'm ready (;21:13
sirmacikhello juju2143 and pleia221:14
juju2143so last Friday, we did classes21:15
=== yofel_ is now known as yofel
juju2143now we'll do inheritance.21:16
juju2143It's one of the advanced features of OOP21:16
juju2143So, like our last example, we created a Person class21:19
sirmacikhmm.. I think I've lost it... could You paste it to some nopaste?21:20
juju2143say you are programming some RPG game, you would like a Warrior or a magician21:20
juju2143So you could create a warrior class and a Magician class21:20
juju2143These classes would be exactly the same, with the exceptions of some methods such as doMagic(), or mana level21:22
juju2143So why not put these methods and attributes in common in the same class?21:24
juju2143I would compare it to the apt-get system of Ubuntu21:24
juju2143like, Warrior and Magician both depends on libperson21:24
=== Pendulum_ is now known as Pendulum
juju2143same thing in C# and in every OOP language that supports inheritance21:25
juju2143the warrior class would include the Person class and take its attributes, etc.21:26
juju2143so open your console application.21:27
juju2143in Main.cs you would have something like this:21:28
juju2143Class Person21:28
juju2143Class Warrior : Person21:29
juju2143class Magician : Person21:29
juju2143(right, the C in class should be lowercased)21:29
juju2143So it's really simple.21:30
juju2143You add this : Person thing21:30
juju2143and you can add methods in Warrior like if you were in Person21:31
juju2143same thing in Magician, but without the methods in Warrior.21:31
juju2143sirmacik, they are not needed, just have a console application handy. And paste the classes in there.21:32
juju2143so if you have this:21:33
juju2143class Person21:33
juju2143public Person(string Sex)21:34
juju2143m_sex = sex;21:34
juju2143public string m_sex = "Male";21:34
juju2143so in your Main() you can instanciate Person like this:21:35
juju2143Person a = new Person("Male");21:35
juju2143you should, even there is nothing in Warrior, instanciate it like Person, just replace Person with Warrior21:36
juju2143So, that's it for inheritance.21:38
sirmaciknice (;21:38
juju2143Now there something else worth mentioning today.21:39
juju2143(damn I forgot what it's called)21:39
juju2143So you can have methods of the same name in same class21:39
juju2143Only difference is the type of return and/or number of arguments.21:40
juju2143(hm, finally, disregard the type of return, the compiler have no way to know which type to return)21:42
juju2143So, say you have a method called doSomething.21:43
juju2143You 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:44
juju2143So you could have endless methods with the same name.21:45
juju2143Also, something interesting with inheritenceyou can do is polymorphism.21:47
juju2143Now you are wondering what's this big word.21:48
juju2143Something you should know is that all classes inherits from System.Object21:48
juju2143something you can do is simply put your Person class in an object21:50
pedro3005juju2143, sorry21:50
juju2143like this: object o = a21:51
juju2143pedro3005, oh no problem21:51
juju2143so it's kinda useful if you have a method, say doSomething, who takes an argument you don't know what ii is21:52
juju2143public void doSomething(object o)21:53
juju2143// do something with o, who would be anything21:54
pedro3005and then could you test upon the type? like if (isint) or something?21:54
juju2143yeah, something like that21:54
juju2143then you can give doSomething a Person or a string21:55
juju2143same thing if you replace object by Person in the above example21:56
juju2143you could give a Warrior or a Magician to your method21:56
juju2143So you transformed your Person into an object21:58
juju2143now to do the inverse you could write this:21:58
juju2143Person p = (Person)o21:58
juju2143(you need to cast it)21:58
pedro3005so you'd be transforming o into a person object?21:59
pedro3005but that's weird21:59
juju2143this is encapsulation.21:59
pedro3005what is o?21:59
pedro3005can you transform anything into a person object?22:00
juju2143o is an object containing a Person22:00
juju2143Person a = new Person("Male");22:00
juju2143object o = a;22:00
juju2143Person p = (Person)o22:01
juju2143like you could do this:22:01
juju2143double a_double = (double)an_integer;22:02
juju2143where an_integer is an int variable22:02
juju2143this is casting (and not castration)22:04
juju2143oh yeah, for the thing with methods of the same name22:06
juju2143it doesn't work well with constructors22:06
juju2143so you have to do this:22:07
juju2143public Person(string arg) : this()22:07
juju2143in fact it works without this() (i think)22:08
juju2143but there you can reuse the constructor without arguments in the constructor with arguments22:08
juju2143so this won't work:22:09
juju2143public Person(string args)22:09
juju2143Person(); // or this();22:09
juju2143it would give an error.22:09
juju2143So I think that's it for today for inheritence and that thing I forgot the name22:11
juju2143for today22:11
juju2143homework: mess with these things22:11
sirmacikare there going to be next lessons?22:11
juju2143i don't know, I think so22:12
juju2143come back tomorrow, we'll see. Maybe we'll do graphics.22:12
sirmacikoh, that'd be great (;22:13
juju2143yep :P22:13
sirmaciksee You then, good night22:14
sirmacik(it's 23:14 here)22:14
juju2143good night.22:16
pedro3005alright juju2143, thanks for the lesson22:18
juju2143your welcome.22:20
ClassBotThere are are 10 minutes remaining in the current session.22:22
pleia2adding next one to the calendar22:22
ClassBotThere are are 5 minutes remaining in the current session.22:25
=== 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

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!