All language subtitles for 010 Creating Classes_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian Download
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:01,380 --> 00:00:06,120 In the last section, we started talking about object oriented programming and d'arte in this section, 2 00:00:06,120 --> 00:00:11,250 we're going to write out a little bit of code to get a better idea of how classes work in Darte later 3 00:00:11,250 --> 00:00:11,340 on. 4 00:00:11,340 --> 00:00:15,570 Throughout the course, we'll have a lot more deeper discussions about object oriented programming and 5 00:00:15,570 --> 00:00:16,710 some of the theory behind it. 6 00:00:16,930 --> 00:00:19,080 But for right now, let's just write a little bit more code. 7 00:00:20,380 --> 00:00:25,420 So to get a better idea of how classes work, you and I are going to create a new class over inside 8 00:00:25,420 --> 00:00:25,720 of D'Arte. 9 00:00:26,530 --> 00:00:32,740 This class is going to model how a person behaves or kind of model a person just by on their own, I 10 00:00:32,740 --> 00:00:33,280 suppose. 11 00:00:34,210 --> 00:00:40,450 Are person class is going to have one piece of data or one field associated with it, which we refer 12 00:00:40,460 --> 00:00:42,340 to as the person's first name. 13 00:00:43,280 --> 00:00:49,580 This first named property or field will have a value of type string, and so just like we had before 14 00:00:49,580 --> 00:00:53,180 in our last application, we were returning a string of Stephen right here. 15 00:00:53,360 --> 00:00:59,180 Essentially, this string is now going to exist on an instance of the person class. 16 00:01:00,280 --> 00:01:05,410 After creating that field will then associate a single method with the person class as well. 17 00:01:05,980 --> 00:01:08,120 We'll call that method print name. 18 00:01:08,650 --> 00:01:13,900 This is going to be a function that takes the person's first name property and then prints it out to 19 00:01:13,900 --> 00:01:14,360 the terminal. 20 00:01:14,920 --> 00:01:20,020 So in total, this is going to be a class that does very similar behavior to the current program that 21 00:01:20,020 --> 00:01:20,950 we have over here. 22 00:01:21,960 --> 00:01:23,220 OK, so let's get started. 23 00:01:23,430 --> 00:01:27,960 It's about back over inside of Arpad, I'm going to highlight all the code that we had before and I'm 24 00:01:27,960 --> 00:01:28,710 going to delete it. 25 00:01:29,480 --> 00:01:33,230 Well, then get started by implementing our person class inside of here. 26 00:01:33,690 --> 00:01:37,780 Remember, every programmer we create has to have a main function. 27 00:01:37,890 --> 00:01:40,920 So at some point in time, we're gonna have to recreate that main function again. 28 00:01:41,190 --> 00:01:44,190 But we'll take care of the class first and then we'll do the main function later. 29 00:01:45,060 --> 00:01:50,940 So to create the person class, I will write out the keyword class and then the name of the class, 30 00:01:50,940 --> 00:01:55,230 which is person notice on using an uppercase name here. 31 00:01:55,350 --> 00:01:59,370 So any time we create a class, we always use an uppercase leading character. 32 00:02:01,010 --> 00:02:07,370 Then inside of the curly braces, we have our class body at the very top or the first couple of lines 33 00:02:07,370 --> 00:02:08,449 inside the class body. 34 00:02:08,479 --> 00:02:14,180 We have the opportunity to declare all the different fields that should be associated with this class. 35 00:02:15,260 --> 00:02:21,560 You and I want to have a single field of type string and the field should have a name of first name, 36 00:02:22,100 --> 00:02:30,950 so to do so or to actually implement that will right out string first name and then a comma or a semicolon 37 00:02:30,950 --> 00:02:31,400 like so. 38 00:02:32,210 --> 00:02:38,330 So this declares a new field of type string called first name on the person class. 39 00:02:39,750 --> 00:02:45,690 Next will add on a method called print name, and any time we call this, we want to log out the value 40 00:02:45,690 --> 00:02:46,830 of this person's name. 41 00:02:48,240 --> 00:02:53,260 Let's go back over inside of D'Arte pad, I can add on a method by writing out the name of the method 42 00:02:53,260 --> 00:02:59,640 first, which is going to be print name, then instead of parentheses and then a set of curly braces. 43 00:03:00,400 --> 00:03:05,830 So this looks like identical syntax to the functions that we were looking at earlier in our last program 44 00:03:05,830 --> 00:03:06,580 that we put together. 45 00:03:07,830 --> 00:03:12,810 Then inside of these curly braces, we can add some code to be executed any time this method runs. 46 00:03:13,260 --> 00:03:16,770 So in this case, we want to printout this person's first name property. 47 00:03:17,550 --> 00:03:21,240 So to do so, I'll write out simply print first name. 48 00:03:23,580 --> 00:03:28,560 Now, one thing you'll notice here is that to reference the first name property that belongs to this 49 00:03:28,560 --> 00:03:31,090 person, we simply wrote out first name. 50 00:03:31,560 --> 00:03:36,990 This is a little bit different than in many other languages, particularly Java or JavaScript, where 51 00:03:36,990 --> 00:03:41,430 you might write out first this DOT and then the actual property name. 52 00:03:42,380 --> 00:03:48,020 This right here, adding into this dot is completely valid syntax inside of dirt, so if you want to 53 00:03:48,020 --> 00:03:52,760 write out long form this dot and then the property name that you're trying to refer to, you absolutely 54 00:03:52,760 --> 00:03:53,210 can. 55 00:03:53,450 --> 00:03:55,190 But it's not required by darte. 56 00:03:55,670 --> 00:04:01,220 If you just write out the property name that you're trying to reference and leave off the this dot dart 57 00:04:01,220 --> 00:04:04,850 is still going to figure out what you're trying to do and kind of fill in the blanks from there. 58 00:04:05,810 --> 00:04:09,450 OK, so this in total has defined our first person class. 59 00:04:09,890 --> 00:04:16,339 Remember, this is just kind of a blueprint of sorts and we can't actually use this just yet for making 60 00:04:16,339 --> 00:04:17,560 use of the person class. 61 00:04:17,570 --> 00:04:21,790 We have to use it to create an object or an instance of that class. 62 00:04:22,280 --> 00:04:28,550 And then once we have that instance, we can actually start to assign or set some data inside the instance. 63 00:04:29,090 --> 00:04:32,180 So let's come back in the next section and we'll take care of that in the next video. 6581

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.