Hey, Jess. Really nice job
helping them with the data structure.
>> Yeah, so we wanted to create a word class that has both translations for
the English and Miwok of the same word.
>> And this is like the floor plan or
the blueprint analogy we used in the last course.
>> Exactly. And so from the same fore-plan,
we could create many different word objects.
>> Okay.
[SOUND] Like this.
This is a word object which represents the number one.
And inside the word object we have two string variables.
A string variable for Miwok translation which is luti, and a string variable for
the English translation which is one.
>> And because this word object was created from this word class,
it's going to have these two methods.
So, the getMiwokTranslation method.
>> Which will translate this string.
>> And getDefaultTranslation method.
>> Which will translate this string.
Okay, cool.
That sounds good.
>> All right, so from the same fore-plan, we can create more and
more words.
So a word for two and a word for three.
>> My gosh, how many words objects?
>> All right, so in the next class,
we're going to take a look at how to write this class definition.
>> Word.
>> Or if you need help you can refer to the simplified version of the TextView
class that we showed you in the last course.
So, remember that we need to provide a constructor for your word class.
And the constructor just looks like a method declaration, but the name of
the method has to match exactly the name of the class, capitalization and all.
So in this case, we have the capital T for text and capital V for
view with no spaces, which matches exactly the name of the class TextView.
Also notice that the constructor has no return type.
Now looking more closely at the constructor for the TextView class,
we see it has the public keyword here.
And this public keyword says that an outside class can access this
constructor.
So for example, an outside color like the MainActivity
can call this constructor using the new keyword and
pass in this input parameter to create a new TextView object.
So note that you can create multiple different constructors for
your class that have different input parameters.
That way any outside color can create a TextView object in a number of
different ways depending on what input parameters they can provide.
Now in the next lesson,
we'll see firsthand how you can create multiple constructors for a class.
So as mentioned earlier, these private and
public words are called access variables.
We first learned about this in the last course.
So they define who has access to these methods or constructors or
even this entire class.
If a method is marked private,
then it can only be called within the enclosing class.
So if something is marked public, it can be accessed from outside the class.
So if the MainActivity wants to create a new text object,
then it can because this class is marked as public.
And it also has a public constructor.
And if any of these variables or methods here are public,
then the MainActivity can call on those as well.
All right, so here's a diagram from the last course if you remember.
If a TextView method is marked as public,
we can access it from both within the TextView class or from outside.
So something like the MainActivity could access it.
In general, it's better to make the variables of the app, so
those that control the state of the object, to be private.
This way you can expose the public methods that modify or
access these variables.
So these methods are called getter and setter methods.
And they give you tighter control over how these variables are modified or
accessed.
So for example, if these state variables were marked as public,
someone could set it invalid color value on the TextView.
And this would cause an unexpected behavior in your class and
maybe even cause your app to crash.
Now in the other hand,
if you have a private color variable with a public setter method,
you can check that the incoming color is valid before updating the state.
Now, go ahead and move on to the quiz where you'll create the word class.