Example 2: The Publisher-Subscriber Protocol - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Example 2: The Publisher-Subscriber Protocol

Description:

Example 2: The Publisher-Subscriber Protocol. Have two collaborating participants. Publisher ... { Publisher is played by TicTacToe ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 9
Provided by: karllie
Learn more at: https://www2.ccs.neu.edu
Category:

less

Transcript and Presenter's Notes

Title: Example 2: The Publisher-Subscriber Protocol


1
(No Transcript)
2
Example 2 The Publisher-Subscriber Protocol
  • Have two collaborating participants

3
Publisher
  • collaboration PublisherSubscriberProtocol
  • participant Publisher
  • import void changeOp(Object args)
  • protected Vector subscribers new
    Vector()
  • export void attach(Subscriber subsc)
  • subscribers.addElement(subsc)
  • export void detach(Subscriber subsc)
  • subscribers.removeElement(subsc)
  • import-export void changeOp()
  • import()
  • for (int i 0 i lt subscribers.size()
    i)
  • ((Subscriber)subscribers.elementAt(i)
    ).
  • newUpdate(this)

4
Subscriber
  • participant Subscriber
  • import void subUpdate(Publisher publ)
  • protected Publisher publ
  • export void newUpdate(Publisher aPubl)
  • publ aPubl
  • subUpdate(publ)

5
Classes for deployment
  • Class Point
  • void set()
  • class InterestedInPointChange
  • void public notifyChange()
  • System.out.println("CHANGE ...")

6
Deployment 1
  • adapter PubSubConn1
  • Publisher is played by Point
  • changeOp is played by set
  • Subscriber is played by InterestedInPointChange
  • void subUpdate(Publisher publ)
  • notifyChange()
  • System.out.println(on Point object "
  • ((Point) publ).toString())

7
Deployment 1
Red expected replaced
Blue from adapter
Point
Publisher
changeOp calls newUpdate attach(Subscriber) deta
ch(Subscriber)
set
InterestedInPointChange
Subscriber
subUpdate(Publisher) newUpdate(Publisher)
subUpdate(Publisher) notifyChange()
8
Deployment 2
  • adapter PubSubConn2
  • Publisher is played by TicTacToe
  • changeOp is played by startGame, newPlayer,
    putMark, endGame
  • Subscriber is played by BoardDisplay,
    StatusDisplay
  • void subUpdate(Publisher publ)
  • setGame((Game) publ)
  • repaint()
Write a Comment
User Comments (0)
About PowerShow.com