On Fri, May 2, 2008 at 6:07 AM, Michael Burton <[EMAIL PROTECTED]> wrote:
>
>  I'm coming to Django from the Java Spring MVC world, and over in those
>  remote lands we have something called a "Service" layer.
>
>  The service layer is responsible for doing all the business logic that
>  your views might otherwise do.  For example, you might have something
>  like:
>
>         class UserService:
>           def create_user(self,...)
>           def create_friendship(self,user_a, user_b)

The difficulty you're having here is that you're trying to write Java
code in Python. :-)

Unless there's something stateful about the UserService, there's no
reason for it to be in a class at all - create_user, create_friendship
etc can just be methods sitting in a module. If you have a whole lot
of services that are logically similar, you might want to split up
your tree thusly:

/myapp
    models.py
    views.py
    /services
        user.py
        invitation.py

and then put your method definitions into user.py and invitation.py as
appropriate, import the 'service modules' as required, and invoke the
methods:

from myapp.services.user import create_user
...
def myview(request):
    ...
    create_user(some, arguments, here)

In short - not everything is an object, if a method doesn't have state
there is no reason for it to be bound to an object, so don't try to.
Inhale deeply the Pythonic goodness, and the world will be a much
groovier place  :-)

>  These services would be instantiated as singletons which would then be

Ah.. the singleton... Java's answer to the fact that not everything is
an object. :-)

If you _really_ need your OO fix, consider this - in Python, modules
are objects anyway, so putting the create_user method in the User.py
module is kinda like creating a singleton User object with a
create_user method.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to