Class: PureMVC::Notification
- Inherits:
-
Object
- Object
- PureMVC::Notification
- Defined in:
- src/patterns/observer/notification.rb
Overview
A base INotification
implementation.
PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does not have an inherent event model.
The Observer Pattern as implemented within PureMVC exists to support event-driven communication between the application and the actors of the MVC triad.
Notifications are not meant to be a replacement for Events in Flex/Flash/Apollo. Generally, IMediator
implementors place event listeners on their view components, which they then handle in the usual way. This may lead to the broadcast of Notification
s to trigger ICommand
s or to communicate with other IMediator
s. IProxy
and ICommand
instances communicate with each other and IMediator
s by broadcasting INotification
s.
A key difference between Flash Event
s and PureMVC Notification
s is that Event
s follow the ‘Chain of Responsibility’ pattern, ‘bubbling’ up the display hierarchy until some parent component handles the Event
, while PureMVC Notification
s follow a ‘Publish/Subscribe’ pattern. PureMVC classes need not be related to each other in a parent/child relationship to communicate with one another using Notification
s.
Instance Attribute Summary collapse
-
#body ⇒ Object?
The body of the notification.
-
#name ⇒ String
readonly
The name of the notification.
-
#type ⇒ String?
The type of the notification.
Instance Method Summary collapse
-
#initialize(name, body = nil, type = nil) ⇒ Notification
constructor
The Notification class represents a message with a name, optional body, and optional type.
-
#to_s ⇒ String
Returns a string representation of the notification.
Constructor Details
#initialize(name, body = nil, type = nil) ⇒ Notification
The Notification class represents a message with a name, optional body, and optional type.
53 54 55 56 57 |
# File 'src/patterns/observer/notification.rb', line 53 def initialize(name, body = nil, type = nil) @name = name @body = body @type = type end |
Instance Attribute Details
#body ⇒ Object?
Returns the body of the notification.
43 44 45 |
# File 'src/patterns/observer/notification.rb', line 43 def body @body end |
#name ⇒ String (readonly)
Returns the name of the notification.
40 41 42 |
# File 'src/patterns/observer/notification.rb', line 40 def name @name end |
#type ⇒ String?
Returns the type of the notification.
46 47 48 |
# File 'src/patterns/observer/notification.rb', line 46 def type @type end |
Instance Method Details
#to_s ⇒ String
Returns a string representation of the notification.
62 63 64 65 66 |
# File 'src/patterns/observer/notification.rb', line 62 def to_s "Notification Name: #{@name}" \ "\nBody: #{@body.inspect}" \ "\nType: #{@type}" end |