ΥڡϤƤʥ֥åޡɲΥڡޤϤƤʥ֥åޡ Υڡlivedoor åפɲΥڡޤlivedoor å

ܼ

Observerѥ

  • 񤤤˴ؤѥΰ
  • ֥Ȥ֤ѤȤˡϢ¿Υ֥ȤˤξѹΤѥ
    • ֥ȤˤƤ뤳Ȥݤˡ֥ȤΤȤ狼褦ˤǤ롣ˡ֥ȤΤ³뤫ɤ򥪥֥Ȥ¹Ի˷뤳ȤǤ롣
  • ListenerȤƤФ롣
  • ֥ȻظǤϴŪ˥ǡϻĤ٤֥ȤäƤ롣󤬤ۤȤϤ٥ǡ򻲾Ȥ뤳Ȥˤʤ뤬ˤäƤΤ餻ʤȤ⤢롣
  • 㤨СExcelΥǡȥդδطMessengerSkypeΥơɽ
  • "Observer"Ȥϡִ¬ԡפȤ̣ġ
  • ObserverѥJDKǺǤ褯Ѥѥ1ġ
  • ֥ȴ֤1¿ΰ¸ط륪֥Ȥξ֤Ѳȡ˰¸Ƥ뤹٤ƤΥ֥ȤưŪΤ칹褦ˤ롣
  • ֥Ȥȥ֥Ф1¿δط롣
    • ֥Ȥξ֤Ѳȥ֥ФΤ뤿ᡢ֥Фϥ֥ȤФư¸롣
    • ΤˤäƤϡ֥Ф⿷ͤ˹礬롣
  • ֥Ȥ֥СˤĤΤäƤΤϡ֥ФΥ󥿥եObserver󥿥եˤƤȤȤǤ롣
    • ߤˤꤹ륪֥ȴ֡ObserverѥǤϥ֥Фȥ֥ȴ֡ˤ·ˤʤäƤ롣
  • ObserverѥѲʬϡ֥֥Ȥξ֡פȡ֥֥ФοȼפǤ롣
    • Observerѥˤꡢ֥Ȥѹ뤳Ȥʤ֥Ȥξ֤˰¸륪֥ȤѤ뤳ȤǤ롣ײȸƤ֡
  • ObserverѥϥݥȤäƥ֥ȤǤդοΥ֥Ф롣δطϤʤ餫ηѾع¤ǤϹۤǤʤݥˤäƼ¹Ի˹ۤ롣
  • JavaȤ߹Observerѥ¸ߤ롣
    • java.util.Observable

ObserverѥΥ饹

Observerѥо줹륵֥ȤϾ֤ݻ椹륪֥ȤǤ롣äơ֤ĥ֥Ȥ1¸ߤ롣
֥ФϾ֤ʤξ֤Ѥ롣֥Ф¿¸ߤ֥Ȥξ֤ѲȤΤƤ餦褦˥֥Ȥ˰ꤹ롣ȥ֥ȤоݤȤƥ֥Ф롣
ʾ夫1ĤΥ֥Ȥ¿Υ֥ФȤδ֤˴ط롣

ʿޡobserver1.jpg

  • Subject󥿥ե
    • ֥ФϿԤơϿ줿֥ФФΤ롣
      • ƥ֥ȤоݤǤʣΥ֥ФĤȤǤ롣
  • ConcreteSuject饹ʶݥ֥ȡ
    • Subject󥿥ե롣
    • ֤ȼΤΥ᥽åɤľ礬롣
  • Observer󥿥ե
    • ֥ФˤʤǽΤΤϤ٤Observer󥿥ե롣
      • Υ饹ޤǤObserver󥿥եupdate()Ȥ᥽åɤΥ᥽åɤSubjectξ֤Ѥ٤˸ƤФ롣
  • ConcreteObserver饹ʶݥ֥С
    • ƥ֥ФϹ뤿ζݥ֥ȤϿ롣

JavaȤ߹Observerѥ

  • java.utilѥåObserver󥿥եObservable饹롣
  • Subject󥿥եObserver󥿥ե̾ObserverѥȻƤ뤬ۤʤ̤ġ
  • ֥ФιȤƥץå巿ȥץ뷿ΤɤǤǽ
  • Observableϥ饹Ǥꡢ󥿥եǤϤʤäơǤϤʤ󥿥եФƥץߥ󥰤򤹤Ȥ֥Ȼظ߷׸§ˤäƤ롣
    • ˡObservable饹ϥ󥿥ե뤳ȤƤʤ
    • Observerϥ饹Ǥ뤿ᡢ֥饹ɬפ롣ΤᡢǤ̤Υѡ饹ĥƤ¸Υ饹ObservableưɲäʤJavaǤ¿ŷѾǤʤˡˤѤβǽ¤롣
  • Observable#setChanged()protectedǤ롣ĤޤꡢObservable򥵥֥饹ʤ¤setChanged()ƤӽФʤ
    • Observable饹Υ󥹥󥹤ݥȤäȼΥ֥ȤΥ󥹥󥹤鹽褦ˤ뤳ȤǤʤϡַѾ⥳ݥ򹥤פȤ֥Ȼظ߷׸§ˤäƤ롣
  • java.util.ObservableǤϡ̤ObserverѥμȤϰۤʤObserverΤ褦notifyObservers()᥽åɤƤ롣

JavaȤ߹ObserverѥΥ饹

ʿޡobserver2.jpg

  • Observable
    • setChanged()᥽åɤƤӽФơ֥Ǿ֤ѲȤɽ롣ơnotifyObservers()ޤnotifyObservers(Object arg)ƤӽФ
      • notifyObservers()ȤХץ뷿ˤʤ롣
    • setChanged()᥽åɤnotifyObservers()ǥ֥Ф򹹿ɬפȤ˻Ѥ롣
      • Υ᥽åɤ򤦤ޤȤȤǡѲΤȤˤϥ֥Ф˹Τ礭ѲΤȤˤϥ֥Ф˹ΤȤȤ¸Ǥ롣
  • ConcreteObservable
    • ֥ФϿΥ᥽åɤϤʤʤʤХѡ饹ObservableѾ뤿ᡣ
  • Observer
    • update᥽åɤΥͥupdate(Observable o, Object arg)Ǥ롣
      • 1ˤΤ֥ȡ2ˤnotifyObservers()Ϥ줿֥Ȥǡ֥ȤꤵƤʤnullˤʤ롣

ʸ

  • Head First ǥѥ