Good work. I'm new to programming.
Look back on the words that have passed by somehow I would like to post a few things that are difficult to understand or that interest me. I hope it will be helpful for those who are wondering what an "interface" is.
If you say it very clearly
Let me give you an example. For example, suppose you have an interface called a control panel. Suppose this control panel has methods called "play", "stop", and "fast forward".
When this controlPanel is implemented
There is an easy-to-understand diagram below, so please refer to it if you like.
References: https://www.gixo.jp/blog/5159/
In summary, the declaration "I promise to implement this function" You should think that.
Is it okay for me to read this and declare it first? Isn't it difficult to expand the function? I thought.
I have a new and easy-to-understand example.
If all the outlets of the above home appliances are unified, you can use the same power strip. There is no need to buy a converter or change the shape of the outlet by performing construction work. To put it the other way around, home appliance developers are forced to "need to unify the shape of outlets," which is the essence of the interface.
Quote source: https://teratail.com/questions/70213
Considering the future as mentioned above, Declare "Make it with such a standard" Isn't the merit very easy to understand?
If the standards are different, we can expect very unfavorable results for usability ...
Now, I would like to touch on extend here as well. For example, suppose you have a person class like this:
class Person {
String name;
eat(){}
```
Inherit this person class and create a Programmer class.
To create a class that inherits from a class, follow the class name
extends class name
Just add.
```java
class Programmer extends Person {
Programming(){}
}
```
This is the use of a parent class called "inheritance".
For the use of the interface, here is
Extends and uses the ** parent method **.
For example, if you want to use the values and behaviors used in the parent method
No need to bother to reproduce the behavior of the parent method again
It can be used by calling (inheriting).
Please note that this is different from the interface.
What did you think.
I hope it will help you understand the interface.
Recommended Posts