夜光序言:
"你女朋友的缺点多不多?"
"像星星一样多"
"那优点呢"
"像太阳一样少"
"那你为什么会选择她?"
"因为太阳一出来星星就消失了啊"
正文:
package com.Genius.first;
/*
*
* @title MyApplet
* @describe 提供run方法~~
* @author hy
* @version
* @date 2019/6/18
*
*/
public interface MyApplet extends Runnable {
}
package com.Genius.first;
/*
*
* @title MyApplet
* @describe 提供run方法~~
* @author hy
* @version
* @date 2019/6/18
*
*/
public interface MyApplet extends Runnable {
}
package com.Genius.first;
/*
*
* @title MyDestination
* @describe 提供write方法~
* @author hy
* @version
* @date 2019/6/18
*
*/
public interface MyDestination {
void write(String string);
}
package com.Genius.first;
import java.io.PrintStream;
public class PrintStreamWriter implements MyDestination {
private PrintStream destination;
public PrintStreamWriter(PrintStream destination){
super();
this.destination = destination;
}
@Override
public void write(String string){
destination = System.out;
destination.println(string);
}
}
package com.Genius.first;
/*
*
* @title StringProvider
* @describe 提供get方法
* @author hy
* @version
* @date 2019/6/18
*
*/
public interface StringProvider {
String get();
}
package com.Genius.first;
public class StringWritingApplet implements MyApplet{
private MyDestination destination;
private StringProvider stringProvider;
public StringWritingApplet(MyDestination destination, StringProvider stringProvider){
super(); this.destination = destination;
this.stringProvider = stringProvider;
}
private void writeString(){
destination.write(stringProvider.get());
}
@Override
public void run(){
writeString();
}
}
package com.Genius.first;
/*
*
* @title Configuration
* @describe 程序启动配置类
* @author hy
* @version
* @date 2019/6/18
*
*/
public class Configuration {
public static MyApplet getMainApplet(){
return new StringWritingApplet(
new PrintStreamWriter(System.out),
new StringProvider() {
@Override
public String get() {
return "hi~~";
}
});
}
}
package com.Genius.first;
/*
*
* @title App
* @describe 启动类,改造helloworld类
* @author hy
* @version
* @date 2019/6/18
*
*/
public class App {
public static void main(String[] args) {
MyApplet mainApplet = Configuration.getMainApplet();
mainApplet.run();
}
}