-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the Factory method design pattern in Portuguese
- Loading branch information
João Victor Bravo
authored and
João Victor Bravo
committed
Oct 14, 2022
1 parent
d533d53
commit 091b8b3
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class animals(): | ||
class galinha(): | ||
info = "Isso é uma galinha" | ||
class cachorro(): | ||
info = "Isso é um cachorro" | ||
class pato(): | ||
info = "isso é um pato" | ||
def fabricar_animais(tipo): | ||
if tipo == "galinha": | ||
return animals.galinha | ||
elif tipo == "cachorro": | ||
return animals.cachorro | ||
elif tipo == "pato": | ||
return animals.pato | ||
else: | ||
raise AssertionError("Tipo de animal não existe") | ||
lista =[] | ||
while True: | ||
info = input("Qual animal você quer na sua fazenda?\n") | ||
animal = fabricar_animais(info) | ||
lista.append(animal.info) | ||
print(lista) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This is a code of Factory Method | ||
|
||
##### This code is written in portuguese, directly from a design pattern subject of my college. | ||
|
||
##### Run code | ||
|
||
python3 factory_method.py | ||
|
||
##### Usage | ||
|
||
Just type the name of one of the classes, and then the code will iterate and will work just like an usual factory method code. |