MVC vs N-tier architecture - Singletons vs Objects (Django/Python) -



MVC vs N-tier architecture - Singletons vs Objects (Django/Python) -

i have class in django responsible speaking service via http. in application beingness used singleton. however, each method requires same 2-3 pieces of info (from user's session) run. in addition, each method has create several calls other methods in class, meaning info gets passed arguments frequently

class mysingletonclass(): def get_user_group(self, email, token): # request service def get_user_picture(self, email, token, pic_id): # request service def get_user_item(self, email, token, item_id): # request service

there 14 methods in , contacted through simple api layer in django. rather passing email , token every time, pass session itself. have either set scoped vars or type lot more characters

def get_user_group(self, session): email = session.get("email") token = session.get("token")

this seems repetitive. solution stop using singleton , instantiate class session info @ api-layer

def my_api_endpoint(request): myobj = myclass(request.session) homecoming httpresponse(myobj.get_user_group()) class myclass(): def __init__(self, session): self.email = session.get("email") self.token = session.get("token") def get_user_group(self): # request service def get_user_picture(self, pic_id): # request service def get_user_item(self, item_id): # request service

however, co-worker said singleton pattern much improve because adheres improve n-tier architecture. hadn't heard term before, after reading mvc v n-tier questions on stackoverflow, still don't seem he's coming from. best can tell n-tier means communicates through intermediary layer rather talking components directly. don't see how not using singletons has made programme worse or less idiomatic.

mvc , n-tier architecture name of lastly implies architectural patterns (not mutualy exclusive).

singleton design pattern.

in application architecture can utilize number of design patterns, according application's utilize cases. utilize cases create 1 or more design patterns optimal implementing them.

in case of singleton, if think there should 1 instance of class in application utilize it, if multiple instances needed or more suitable, don't. criteria.

so no, did not nil wrong,

python django model-view-controller architecture n-tier

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -