From 3234323e90549ce2a9ae9576b99ee198e3a9fe8f Mon Sep 17 00:00:00 2001 From: chuoru Date: Tue, 11 Aug 2020 10:04:06 +0900 Subject: [PATCH] #1 add duck typing --- DesignPattern/Decorator/duck_typing.py | 10 ++++++++++ DesignPattern/Decorator/formatting_tool.py | 1 + 2 files changed, 11 insertions(+) diff --git a/DesignPattern/Decorator/duck_typing.py b/DesignPattern/Decorator/duck_typing.py index 857720b..eca56de 100644 --- a/DesignPattern/Decorator/duck_typing.py +++ b/DesignPattern/Decorator/duck_typing.py @@ -15,3 +15,13 @@ # 内部ライブラリ + +class Specialstring: + def __len__(self): + return 21 + + +# Driver's code +if __name__ == "__main__": + string = Specialstring() + print(len(string)) diff --git a/DesignPattern/Decorator/formatting_tool.py b/DesignPattern/Decorator/formatting_tool.py index a349d63..c1065bc 100644 --- a/DesignPattern/Decorator/formatting_tool.py +++ b/DesignPattern/Decorator/formatting_tool.py @@ -61,6 +61,7 @@ def render(self): if __name__ == '__main__': before_gfg = WrittenText("GeeksforGeeks") + after_gfg = ItalicWrapper(UnderlineWrapper(BoldWrapper(before_gfg))) print("before :", before_gfg.render())