Inline answers follow...
On 23 October 2016 at 10:01, Andrew <
randomshi...@gmail.com> wrote:
> Tried to look up service layers, but couldn't find examples of how it was
> supposed to look like - is it supposed to be like a class, and I toss the
> lead into it and it handles business logic and saving?
Keep in mind we're talking about Python, OK? Then, you should not
create a class if you don't need it. Simple functions work nice many
times.
A service layer is just another layer. Your view and template is on
the "web" layer. A service layer would be on the "business" layer,
between your user interface and your domain model. No secret in it.
Just another class or function in another package or module.
See this overview for clarification:
http://martinfowler.com/eaaCatalog/serviceLayer.html
There's no "the right way" to do it. No silver bullet. Design varies
from person to person, but I strongly advocate for thin views
according to the Single Responsibility Principle, i.e, letting views
gather (call) workers (the service layer) to do the "dirty work" and
return a response to user. Nothing more.
>
> Normally I'd use ipinfo.result myself, but I read somewhere about separating
> the interface from the internals of the class, so I don't have classes
> everywhere depending on this variable having this name in IPInfo.
Interfaces are a conceptual stuff. Python doesn't have a word or
structure for them. No additional complexity.
You can emulate interfaces creating a class implementing public
methods (names don't start with an underscore) and simply raising
NotImplementedError. It's children should implement these real
methods.
Some example (Python 3):
class MyInterface:
def do_something(self):
raise NotImplementedError("Must be implemented in child class")
class MyClass(MyInterface):
def __init__(self):
# do some initialisation
def do_something(self):
# real implementation
def _some_private_method(self):
# do something
You see good examples of "programming to an interface" concept when
you read about magic methods in Python docs. These "interfaces" are
expected to make your own comparisons, evaluating True/False or object
length and so on. See docs here:
https://docs.python.org/3/reference/datamodel.html#special-method-names
--
Cheers.
Vinicius Assef
>> > email to
django-users...@googlegroups.com.
>>
django-users...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
django-users...@googlegroups.com.
>
https://groups.google.com/d/msgid/django-users/CAEam--U9vTBE1xsvVxMHXPjx_z%2B69bJcUBXFjNEeF7iLD%2B3Xcg%40mail.gmail.com.