デザインパターン
せっかくオブジェクト指向やるので、デザインパターンも使ってみよう。
GUIの共通パラメータ(XMLドキュメント,GUIのステータス)を構造体として持たせて、こいつはグローバル変数にしたいのだが、オブジェクト指向的にやるとsingletonなるものを使うらしい。
Pythonでのsingletonの使い方。
http://d.hatena.ne.jp/jmax/20041120
を参考にサンプルを。
#!/usr/bin/python
class seeditStatus(object):
def __new__(type):
if not '_the_instance' in type.__dict__:
type._the_instance = object.__new__(type)
return type._the_instancedef setData(self,d):
self.data = d
def getData(self):
return self.dataa = seeditStatus()
b = seeditStatus()
print a
print b
結果。
<__main__.seeditStatus object at 0xb7f6e3cc>
<__main__.seeditStatus object at 0xb7f6e3cc>
と出力された。aもbも同じインスタンスを参照していることが分かる。
で、メンバ変数「data」に
グローバル変数を持たせる。