This time I dealt with ** Java dependencies **.
** "Dependent" ** simply means ** "using another class" **. Specifically, if either of the following two applies, it can be said that there is a dependency.
--Has another class as a local variable --Other classes are method arguments and return values
For example, let's take a bento as an example. There is rice in the lunch box. There are many other side dishes, but for the sake of simplicity, let's just take rice as an example. Then the code would look like this:
--Bento class
//Bento class
public class Bento {
private Gohan gohan;//rice
//constructor
public class Bento(Gohan gohan) {
this.gohan = gohan;
}
}
This bento class is filled with rice. The code to make this bento (new) is as follows.
--Main class
public class Main {
public static void main(String[] args) {
//Generation of rice (instantiation)
Gohan gohan = new Gohan();
//Bento generation (instantiation)
Bento bento = new Bento(Gohan);
}
}
In this way, the fact that one ** class uses another ** is called ** dependency **.
Quote: Dripcoke
Recommended Posts