夜光:@guice依赖注入(二)

48 篇文章 59 订阅
39 篇文章 38 订阅

 

 

夜光序言:

 

 

"你女朋友的缺点多不多?"

"像星星一样多"

"那优点呢"

"像太阳一样少"

"那你为什么会选择她?"

"因为太阳一出来星星就消失了啊"

 

 

 

 

 

正文:

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();
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值