03 Oct '13, 2am

Segue um artigo bem conciso sobre Decorators:

The system obeys the Tell don’t Ask principle where you should tell an object to do something as opposed to extracting data from it and implementing behavior on the caller code. Here, instead of asking a monkey if it is eating in order to display a state message, we tell it to give us the message simplifying and removing branches from the client code. By not polluting the Monkey model, we’re also obeying the Single Responsability Principle where every object should have only one responsability and it should be encapsulated by one class. The Monkey class handles database finders, field abstraction, and data consistency via validations, not more than that. On the other hand, the decorators handle presentation related state and logic while delegating to Monkey when appropriate. Finally, it obeys the Open/Closed Principle where each object is open for extension but closed for ...

Full article: http://robots.thoughtbot.com/post/13641910701/tidy-views-...

Tweets