Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we started talking about object oriented programming and d'arte in this section,
we're going to write out a little bit of code to get a better idea of how classes work in Darte later
on.
Throughout the course, we'll have a lot more deeper discussions about object oriented programming and
some of the theory behind it.
But for right now, let's just write a little bit more code.
So to get a better idea of how classes work, you and I are going to create a new class over inside
of D'Arte.
This class is going to model how a person behaves or kind of model a person just by on their own, I
suppose.
Are person class is going to have one piece of data or one field associated with it, which we refer
to as the person's first name.
This first named property or field will have a value of type string, and so just like we had before
in our last application, we were returning a string of Stephen right here.
Essentially, this string is now going to exist on an instance of the person class.
After creating that field will then associate a single method with the person class as well.
We'll call that method print name.
This is going to be a function that takes the person's first name property and then prints it out to
the terminal.
So in total, this is going to be a class that does very similar behavior to the current program that
we have over here.
OK, so let's get started.
It's about back over inside of Arpad, I'm going to highlight all the code that we had before and I'm
going to delete it.
Well, then get started by implementing our person class inside of here.
Remember, every programmer we create has to have a main function.
So at some point in time, we're gonna have to recreate that main function again.
But we'll take care of the class first and then we'll do the main function later.
So to create the person class, I will write out the keyword class and then the name of the class,
which is person notice on using an uppercase name here.
So any time we create a class, we always use an uppercase leading character.
Then inside of the curly braces, we have our class body at the very top or the first couple of lines
inside the class body.
We have the opportunity to declare all the different fields that should be associated with this class.
You and I want to have a single field of type string and the field should have a name of first name,
so to do so or to actually implement that will right out string first name and then a comma or a semicolon
like so.
So this declares a new field of type string called first name on the person class.
Next will add on a method called print name, and any time we call this, we want to log out the value
of this person's name.
Let's go back over inside of D'Arte pad, I can add on a method by writing out the name of the method
first, which is going to be print name, then instead of parentheses and then a set of curly braces.
So this looks like identical syntax to the functions that we were looking at earlier in our last program
that we put together.
Then inside of these curly braces, we can add some code to be executed any time this method runs.
So in this case, we want to printout this person's first name property.
So to do so, I'll write out simply print first name.
Now, one thing you'll notice here is that to reference the first name property that belongs to this
person, we simply wrote out first name.
This is a little bit different than in many other languages, particularly Java or JavaScript, where
you might write out first this DOT and then the actual property name.
This right here, adding into this dot is completely valid syntax inside of dirt, so if you want to
write out long form this dot and then the property name that you're trying to refer to, you absolutely
can.
But it's not required by darte.
If you just write out the property name that you're trying to reference and leave off the this dot dart
is still going to figure out what you're trying to do and kind of fill in the blanks from there.
OK, so this in total has defined our first person class.
Remember, this is just kind of a blueprint of sorts and we can't actually use this just yet for making
use of the person class.
We have to use it to create an object or an instance of that class.
And then once we have that instance, we can actually start to assign or set some data inside the instance.
So let's come back in the next section and we'll take care of that in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.