Projekat

Općenito

Profil

Akcije

Podrška #19840

Zatvoren

pivot ui, eventbus - publisher/subscriber model

Dodano od Ernad Husremović prije oko 16 godina. Izmjenjeno prije oko 16 godina.

Status:
Zatvoreno
Prioritet:
Normalan
Odgovorna osoba:
Kategorija:
-
Početak:
04.03.2010
Završetak:
% završeno:

0%

Procjena vremena:
Akcije #1

Izmjenjeno od Ernad Husremović prije oko 16 godina

  • Naslov promijenjeno iz pivot ui, eventbus - pub u pivot ui, eventbus - publisher/subscriber model
Akcije #3

Izmjenjeno od Ernad Husremović prije oko 16 godina

The EventBus library is a mature, well-tested and very well-documented pub/sub API with annotations. It can be used in any JavaSE application, not just UIs. The EventBus sticks to a single VM, hence it does not compete with JMS, but is often used by JMS consumers to broadcast events through an application. The EventBus is very lightweight and be used piecemeal alongside an existing codebase. The EventBus works with POJOs, so you can immediately publish any Object that you are working with today. This differentiates the EventBus from Java Observer, Java Events, and every other pub/sub API for any platform. The EventBus does not impose any requirements on what is published. This a key reason why the EventBus requires minimal amounts of code and is extremely non-invasive.

Akcije #5

Izmjenjeno od Ernad Husremović prije oko 16 godina

The SymbolPane is the publisher - it creates the event and notifies any other interested parties, which for now, is just the master controller.

Akcije #6

Izmjenjeno od Ernad Husremović prije oko 16 godina

One of the strongest designs for pub/sub in UIs is decoupling the data model from the UI components that are interested in the data. Without pub/sub, components typically register their interest with a DataManager and ask to be called back. Instead of wiring hard listeners, pub/sub uses the Hollywood Principle - "Don't call us, we'll call you." This avoids a lot of work in managing what is listened to as UI components come and go or as the data they are interested in changes.

Akcije #7

Izmjenjeno od Ernad Husremović prije oko 16 godina

The EventBus is the common name for this pattern, though in Fowler's EventCollaboration, he calls it a MessageBus (which is more apt, but less in line with convention).

Akcije #8

Izmjenjeno od Ernad Husremović prije oko 16 godina

Validation Through Veto

The second requirement - displaying information about duplicate symbols - is outside of the realm of the text component, so the EventBus is a good choice.

The EventBus provides veto subscribers that can stop events from being published. The VetoSubscriber interface has one method, boolean shouldVeto(event), which returns true to veto the event, false to let it get published. The EventBus checks all VetoSubscribers before any regular subscribers are called. This is a distinct advantage over Swing's PropertyChange Veto mechanism, where a veto can occur after some listeners have already been called, forcing the developer to code impossible rollback mechanisms.

Akcije #9

Izmjenjeno od Ernad Husremović prije oko 16 godina

We've seen some WTKX and some of the Pivot niceties. Let's finishing by publishing an event on the EventBus from WTKX instead of Java. I haven't figured out how to create a class EventSubscriber in Javascript, but publishing is quite easy. The addSymbol() method we've been working with is a good example since it's called from both the add button and the enter key. Let's stay DRY and move both calls to WTKX:

Akcije #10

Izmjenjeno od Ernad Husremović prije oko 16 godina

Hopefully you understand how the EventBus is a great tool for user interface development. It can be used to simplify code, attain true component design, reduce coupling and gain cohesion.

Hopefully you also learned something about the new Pivot RIA and the productive development model it presents.

Programming with pub/sub often takes some getting used to since it's a different mindset from the traditional callstack. It is worth the effort. The StockTracker application is quite small and was improved by using pub/sub. The benefits of pub/sub grow non-linearly with the size and complexity of the application.

Akcije #11

Izmjenjeno od Ernad Husremović prije oko 16 godina

scala traits

http://blog.objectmentor.com/articles/2008/09/27/traits-vs-aspects-in-scala

Scala traits provide a mixin composition mechanism that has been missing in Java. Roughly speaking, you can think of traits as analogous to Java interfaces, but with implementations.

Aspects, e.g., those written in AspectJ, are another mechanism for mixin composition in Java. How do aspects and traits compare?

Let’s look at an example trait first, then re-implement the same behavior using an AspectJ aspect, and finally compare the two approaches.

Akcije #12

Izmjenjeno od Ernad Husremović prije oko 16 godina

  • Status promijenjeno iz Dodijeljeno u Zatvoreno
Akcije

Također dostupno kao Atom PDF