stories
stories copied to clipboard
Story methods should not know implementation details.
def a1s1(self, state):
self.send_message() # good
def a1s1(self, state):
send_message() # bad
We should not know if it will be an asterisk client or twilio api call.
It should be injected by the place where we called the story.
P.S. access to the current time is the same as access to the database.
Database layer errors
Service objects should not know any details about database layer.
Even does not know what kind of exceptions it could possibly raise.
Otherwise, it would be strong coupling with implementation detail.
There are two options to avoid this.
-
Null-object. A database layer will return null which will be converted to a null-object by state contract. This object will raise an exception when we use it. According to Liskov substitution principle.
User.Null() - Status flag. Implementation could say if operation was successful or not with boolean. Story would raise application level error in that case.
def story_step(self, state): ok, result = load_user(1) if ok: state.user = result else: return Failure(result)
The main point here, service layer should not know about error details in the database layer.
Database layer should not instantiate entities itself, or it will limit its usage among different stories.
Database layer should always catch database exceptions.