jueves, 17 de septiembre de 2015

Practical object oriented -Sandi metz

I've finished today the book. Just to write a list of the top things within the book:
Asking for what instead of telling how
Seeking context independence
She uses the example of mechanics and Trip. Where a trip is prepare if its bikes are prepare. There are two knowledge levels here. One is  how to prepare a bike (pump the tires, check chain...). The other is how to prepare a trip. Which is by preparing each of his bikes. Both responsibilities correspond to the Mechanic. In order todo that a mechanic knows that a trip has bikes. But we could abstract this concept into a preparable , where something can be preparable is it has bikes. This avoids the preparing knowledge from leaking into the trip class.
Notice that in order to achieve this we have to different kinds of interfaces. On one side we have a mechanic (preparator), exposes command methods, which allow to tell the what not the how. But on the other we have something preparable, which responds to query methods.
I though that this kind of query concept was wrong, and was looking always for the command like concept.  However it does make sense in situation like this where preparing is domain heavy concept which needs to be extracted from bike AMD put into a service. Then the dilemma is whether trip passes bikes and makes the service more context independent (he doesn't works with something that has  bikes, he works with bikes directly). In this case the trip knows that are his bikes the thing that need Ti be prepare.
The other. Trip seems that. Still know that the bikes. Are prepare since  still needs to respond tio bikes as a preparable.
But un tje example mechanic ask for the bikes,vehicles and something else from the trip so it totally make sense to pass the wrapping object trip.

Remove argument order dependency with a has table

Inheritance
Decoupling subclasses using hook messages (post_initialise)
It removes. The super from subclasses and therefore the knowledge within the subclass of the superclass

Query versus command important for testing

No hay comentarios:

Publicar un comentario