2007-08-01から1ヶ月間の記事一覧

PythonでFactory Methodパターン

Factory Methodパターンを使うと,実際に作成するオブジェクトの種類や作成手順を隠蔽できます. たとえば次の例だと,Counterオブジェクトが生成されるのか,それともCounterWithRealNumberオブジェクトが生成されるのかを,そのオブジェクトを利用する側で…

PythonでPrototypeパターン

Prototypeパターンではあるオブジェクトをコピーすることで新しいオブジェクトを作成する. 実装するには,属性値をコピーして新しいオブジェクトを返すメソッドを定義する. #!/usr/bin/python class Prototype(object): def __init__(self, prototype = No…

PythonでSingletonパターン

#!/usr/bin/python class SingletonClass(object): __instance = None; def __new__(cls): if not cls.__instance: cls.__instance = object.__new__(cls); return cls.__instance; def __init__(self): self.value = 0; def increment(self): self.value +=…

しばらくPythonから離れていました.デザインパターン復習中です.昔Javaで覚えたので,Pythonでリハビリします.