English 中文(简体)
CDI - 活动观察员
原标题:CDI - Event Observers

我有所有观察同一事件的活动观察员,因此我有一个观察这一事件的抽象超级大队,然后是次流压/执行具体功能。

问题在于,除非我把活动观察员方法放在次级别上(这不符合我的设计目的),否则它就没有观察活动。

我当然能够这样做,但我希望尽可能少地写法。

它是否应当这样做(我做一些其他错误的事情吗?)

如果要这样做,我就可以写上一件事的生产者,然后是拦截者。 我认为,我的第一个做法比较简单,而且更有可能被其他开发商适当使用。

例如:

SuperClass:

public abstract class AbstractFileWriter
{
  public void onReady(@Observes ReadyEvent readyEvent)
  {
    try
    {
      handleReady(readyEvent, ...);
    }
  }

  protected abstract handleReady(ReadyEvent readyEvent, otherParameters go here);
}

SubClass

public class XmlWriter extends AbstractFileWriter
{
   protected handleReady( ... )
   { ... }
}

如果我这样写的话,就永远不会援引Ready(在这个问题上,两者都不会重新使用);然而,如果我用子类内的观察方法书写,它就能够发挥预期的作用。 我想这样写一下,因为只有少得多的法典一(d)才需要写字,而稍微少一点的抽象性,可以更容易理解。

Walter

最佳回答

正如我前面提到的那样,我写了一位勋章。 这实质上是一样的,只是稍微不同写的。

Walter

问题回答

要么宣布超级舱内相关方法为抽象方法,要么将其称为每个子流层使用的抽象“详细”方法。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签