Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:将装饰类添加到现有实现中_Java_Oop_Inheritance_Decorator - Fatal编程技术网

Java:将装饰类添加到现有实现中

Java:将装饰类添加到现有实现中,java,oop,inheritance,decorator,Java,Oop,Inheritance,Decorator,目前我有以下设置(为了保持小规模,我没有发布所有注释): 现在,我正在尝试向这个实现中添加一个decorator类,在调用之前可以执行其他操作(例如,访问检查或日志记录等) 因此,我尝试创建一个decorator类,它可以执行f.ex。在调用实际实现之前进行日志记录 @Singleton public class MessageDecorator implements MessageService { @Inject private final MessageService messag

目前我有以下设置(为了保持小规模,我没有发布所有注释):

现在,我正在尝试向这个实现中添加一个decorator类,在调用之前可以执行其他操作(例如,访问检查或日志记录等)

因此,我尝试创建一个decorator类,它可以执行f.ex。在调用实际实现之前进行日志记录

@Singleton
public class MessageDecorator implements MessageService {
  @Inject
  private final MessageService messageService;

  @Override
  public String getAllMessages() {
    // here we can log
    return messageService.getAllMessages();
  }
}
项目正在编译,没有问题,但是调用getAllMessages()方法,没有调用decorator,进程(工作)与以前一样,但是没有记录任何内容

老实说,我被卡住了,我曾经看到过一个这样的工作示例,但我不再确切地记得与我的方法有什么不同,或者我在哪里犯了错误/忘记了更改某些内容

@Singleton
public class MessageDecorator implements MessageService {
  @Inject
  private final MessageService messageService;

  @Override
  public String getAllMessages() {
    // here we can log
    return messageService.getAllMessages();
  }
}