The Meaning and Usage of java Static Agent
- 2021-09-20 20:36:52
- OfStack
Description
1. If the proxy exists before the program runs, then this proxy becomes a static proxy. In this case, the proxy is usually defined by us in Java code.
2, 1 Generally speaking, the proxy class and delegate class in a static proxy will implement the same interface or give birth to the same parent class.
Instances
/**
* Both the delegate class and the proxy class implement the Sell Interface
*/
public interface Sell {
void sell();
void ad();
}
Instance extension:
In Java, agent is also such a concept. Let's look at a chestnut:
First, create a star class Stars:
public class Stars implements IStars{
private String name;
public Stars(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void sing(){
System.out.println(getName() + " Sing 1 A song .");
}
public void dance(){
System.out.println(getName() + " Jump 1 Dance .");
}
}
This is the corresponding interface:
public interface IStars {
void sing();
void dance();
}