MVC vs N-tier architecture - Singletons vs Objects (Django/Python) -
I have a class in Django which is responsible for speaking to any other service through http. It is being used as a singleton. However, each method requires 2-3 pieces (from the user's session) similar to the data to run. Additionally, each method has to make a number of calls to other methods in the class, which means that the data is often passed in the form of debates
class MySingletonClass (): def get_user_group ( Request for #def_user_picture (auto, email, token, pick_id): service request #def get_user_item (auto, email, token, item_id): # request for service
all about 14 ways and they have a simple API layer Area through the contact. Instead of passing email
and token
every time, I could just pass session
but then I would either need to set up a scrolled war or Too many characters must be typed
def get_user_group (auto, session): email = session.get ("email") token = session.get ("token")
It seems to be repeatable that my solution was to stop using a singleton and instantiate the class with session information on the API layer
def my_api_endpoint (A MyObj = myClass (request.session) Returns HttpResponse (myObj Get_user_group ()) Class MyClass (): def __init __ (auto, session): self.email = session.get ("email") self.token = session .get ("token") def get_user_group (auto): # request service def get_user_picture (auto, pic_id): # def get_user_item (self, item_id) request for service: # request for service
However, my co-worker said that the singleton pattern is much better because it is better for N-level architecture. I did not hear the first word, but after reading all the MVC v n-tier
questions on the stack overflow, I still do not think where it is coming from, the best I can tell the n-tier I mean that it means that everything communicates directly through the intermediary layer instead of talking to the components. I do not see that using loneliness has made my program poor or less idiotic.
The name of the last as MVC and N-level architecture is not the architectural pattern (not even exclusive).
Singleton is a design pattern.
In an application with a fixed architecture, you can use any number of design patterns, according to the application usage cases. The cases of this use make one or more design patterns optimal for implementing them.
In the case of singleton, if you think that in your application should be just one example of that class, then you use it, if many examples are required or more suitable, then you do not We do. It's just the criteria
Not so, you did not do anything wrong,
Comments
Post a Comment