일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- SSH
- postgresql
- python
- FIND
- autovacuum
- sql
- sqlite
- conda
- 쉘
- List
- expect
- pandas
- mysql
- Shader
- C++
- with
- if
- Eclipse
- awk
- SVN
- ubuntu
- dataframe
- DROP
- pi
- 배열
- ngui
- null
- boost
- Unity
- c++11
Archives
- Today
- Total
その先にあるもの…
observer 본문
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
namespace pattern { class Subject { private Listm_Observer; virtual public void Add( Observer o) { m_Observer.Add( o ); } virtual public void Del( Observer o) { m_Observer.Remove( o ); } virtual public void notify() { for( int i = 0; i < m_Observer.Count; i++ ) { m_Observer[i].notify( this ); } } public Subject() { m_Observer = new List (); } } class mainCharacter : Subject { int hp = 100; int mp = 100; public int HP { get{ return hp; } set{ hp = value; notify();} } public int MP { get{ return mp; } set{ mp = value; notify();} } } class Observer { public Observer() {} public virtual void notify( Subject s) {} } class HP : Observer { public override void notify(Subject s) { mainCharacter character = (mainCharacter)s; Console.WriteLine( character.HP); } } class MP : Observer { public override void notify(Subject s) { mainCharacter character = (mainCharacter)s; Console.WriteLine( character.MP); } } class MainClass { public static void Main (string[] args) { mainCharacter character = new mainCharacter(); HP hp = new HP(); MP mp = new MP(); character.Add( hp ); character.Add( mp ); character.HP = 70; } } }
도움 : http://www.dofactory.com/Patterns/PatternObserver.aspx#_self1
Comments