Skip to content

Commit ad6fd4b

Browse files
author
Mateus Furquim
committed
Add Protocol to factory pattern
1 parent cc54961 commit ad6fd4b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎patterns/creational/factory.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
*TL;DR
2222
Creates objects without having to specify the exact class.
2323
"""
24+
fromtypingimportDict
25+
fromtypingimportProtocol
26+
fromtypingimportType
27+
28+
29+
classLocalizer(Protocol):
30+
deflocalize(self, msg: str) ->str:
31+
pass
2432

2533

2634
classGreekLocalizer:
@@ -41,10 +49,10 @@ def localize(self, msg: str) -> str:
4149
returnmsg
4250

4351

44-
defget_localizer(language: str="English") ->object:
52+
defget_localizer(language: str="English") ->Localizer:
4553

4654
"""Factory"""
47-
localizers={
55+
localizers: Dict[str, Type[Localizer]]={
4856
"English": EnglishLocalizer,
4957
"Greek": GreekLocalizer,
5058
}

0 commit comments

Comments
(0)