** "Array is an array in the first place, isn't it? ArrayList is also an array, isn't it !?" **
I don't think this is just me.
I think that you will understand it empirically as you use it, but if you do not understand it properly, you may be in trouble.
I will make a note of my own understanding, so I hope it will help beginners to imagine a little difference.
The point is that ** data and processing are handled as a unit **.
I didn't know this at first, and I'm still not sure if it's so useful. .. ..
It is often explained by car, but in the end it was indigestion with ** "I understand what you are saying ..." **.
However, in the end, it was refreshing to think of it as a ** template **.
Even if a beginner tells me that I can't use it unless I instantiate it into a class, I think it's kind of a mess.
By car
Integrate these things together as a class
Even if it is said that the class will be available by doing so.
Is it possible to instantiate the process of running and operate the stored variables below? I don't understand even if I write it.
However, if you think of it as a template in the first place, it will be refreshing.
Let's make a car! When I thought ** Vehicle type: Devil ** ** Displacement: 100 million ** ** Fuel: Crude oil **
** Good made! Let's sell it! What about the price? ** **
Is that a problem? The person who talks about making a car at the first stage must be a different person at that time. If there is no decision at that time, the first decision will be a problem for each person if it depends on the person.
So, let's make a car class template here Vehicle type Displacement fuel price color speed Run Stop Back Please decide first! By doing so, there is no such thing as "I wasn't able to decide this" or "What was the decision?"
So, according to this template, it is instantiation to decide "Then let's make the car model a devil!"
Strictly different, but I think this understanding is almost okay.
As for the processing, instead of deciding how fast the running process should move for each design, first decide the value of speed and use that speed value, ** "This If you make a template saying "Go forward at about the speed" **, it feels like you can run properly with the same command every time.
Therefore, rather than collecting only the values like an array, if you also summarize the processing of what to do with those values, the description will be unified.
If you think of it as a template, it's convenient.
When retrieving variables in a class Class name.Variable name So, in order to retrieve the number of elements in the array, the number of elements is contained in the variable called length in the array class.
array.length
You can take it out by doing like.
Variables cannot be accessed directly when encapsulated. Because
array.length
Even if you write like this, it will only result in an error.
Then, what should I do? I use ** methods ** such as getters and setters, which are mentioned in the explanation of encapsulation, to get the value of a variable.
The miso is that you have to use a method.
That is, when getting the number of elements
array.size();
It means that ** () ** is required at the end like. Because it's a method.
Since the writing method is different depending on whether you are using a method or specifying a variable name to get it, rather than remembering that "it works if you write this for the time being", "whether you are using a method or specifying a variable name If you don't know the difference between "or", you may be wondering whether to add ().
For the time being, I wrote it with the intention of organizing my head. It's not a strict explanation, but I hope that the vague image will turn into a slightly cleaner image.
Also, I would like to summarize this story in a separate article.
Recommended Posts