Class: PureMVC::Notification

Inherits:
Object
  • Object
show all
Defined in:
src/patterns/observer/notification.rb

Overview

A base INotificationimplementation.

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, IMediatorimplementors place event listeners on their view components, which they then handle in the usual way. This may lead to the broadcast of Notifications to trigger ICommands or to communicate with other IMediators. IProxy and ICommand instances communicate with each other and IMediators by broadcasting INotifications.

A key difference between Flash Events and PureMVC Notifications is that Events follow the ‘Chain of Responsibility’ pattern, ‘bubbling’ up the display hierarchy until some parent component handles the Event, while PureMVC Notifications 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 Notifications.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, body = nil, type = nil) ⇒ Notification

The Notification class represents a message with a name, optional body, and optional type.

Parameters:

  • name (String)

    the name of the notification

  • body (Object, nil) (defaults to: nil)

    optional data to pass with the notification

  • type (String, nil) (defaults to: nil)

    optional type identifier



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

#bodyObject?

Returns the body of the notification.

Returns:

  • (Object, nil)

    the body of the notification



43
44
45
# File 'src/patterns/observer/notification.rb', line 43

def body
  @body
end

#nameString (readonly)

Returns the name of the notification.

Returns:

  • (String)

    the name of the notification



40
41
42
# File 'src/patterns/observer/notification.rb', line 40

def name
  @name
end

#typeString?

Returns the type of the notification.

Returns:

  • (String, nil)

    the type of the notification



46
47
48
# File 'src/patterns/observer/notification.rb', line 46

def type
  @type
end

Instance Method Details

#to_sString

Returns a string representation of the notification.

Returns:

  • (String)


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