Created
September 26, 2021 01:56
-
-
Save anuradhawick/9bed6ad3b70bbe4f8c1fb7ac23bd3f9d to your computer and use it in GitHub Desktop.
Factory Design Pattern
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
class User: | |
def __init__(self, *args, **kwards): | |
self.store = args | |
self.key_store = kwards | |
def __str__(self): | |
output = 'Values\n-------\n' | |
for v in self.store: | |
output += str(v) + '\n' | |
output += 'Keys\n-------\n' | |
for k, v in self.key_store.items(): | |
output += f'{k:10}\t{str(v):5s}\n' | |
return output | |
class Admin(User): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
def admin_func(self, task): | |
# TODO admin logic | |
pass | |
class Guest(User): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
def guest_func(self, task): | |
# TODO guest logic | |
pass | |
def get_user(type='guest', *args, **kwargs): | |
switch = { | |
'guest': Guest, | |
'admin': Admin | |
} | |
return switch[type](*args, **kwargs) | |
admin = get_user('admin', 'Anuradha', age=25, subject='CS') | |
print(admin) | |
print() | |
admin = get_user('guest', 'Vijini', age=25, subject='Biology') | |
print(admin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment