public interface ViewModel
Interface for a View Model.
You can use a notification mechanism by using the publish(String, Object...)
method. In the View you can
subscribe to this notifications by using viewModel.
subscribe(String messageName, NotificationObserver observer)
.
Some additional hints to this layer:
Never create a dependency to the view in this layer - if you have to create a new view after a business step, notify
the view with the NotificationCenter
or a callback that the view can create the new view. When you write a
new View
you should create the associated ViewModel
with tests before.
Modifier and Type | Method and Description |
---|---|
default void |
publish(String messageName,
Object... payload)
Publishes a notification to the subscribers of the messageName.
|
default void |
subscribe(String messageName,
NotificationObserver observer)
Subscribe to a notification with a given
NotificationObserver . |
default void |
unsubscribe(NotificationObserver observer)
Removes the observer for all messages.
|
default void |
unsubscribe(String messageName,
NotificationObserver observer)
Remove the observer for a specific notification by a given messageName.
|
default void publish(String messageName, Object... payload)
This notification mechanism uses the NotificationCenter
internally with the difference that messages send
by this method aren't globally available. Instead they can only be received by this viewModels subscribe(String, NotificationObserver)
method or when using this viewModel instance as argument to the NotificationCenter.subscribe(ViewModel, String, NotificationObserver)
method.
See NotificationTestHelper
for a utility that's purpose is to simplify unit tests with notifications.
messageName
- of the notificationpayload
- to be senddefault void subscribe(String messageName, NotificationObserver observer)
NotificationObserver
.
The observer will be invoked on the UI thread.messageName
- of the Notificationobserver
- which should execute when the notification occursdefault void unsubscribe(String messageName, NotificationObserver observer)
messageName
- of the notification for that the observer should be removedobserver
- to removedefault void unsubscribe(NotificationObserver observer)
observer
- to be removedCopyright © 2015 Saxonia Systems AG. All rights reserved.