Tuesday, November 11, 2014

Proxy Pattern -- one way out of many towards Clean Architecture


Earlier this year, I bought several of the Clean Coders screencasts, which motivated me to implement a clean architecture in Rails.  It also motivated me to read Uncle Bob's classic text, Agile Software Development: Principles, Practices, and Patterns. I've known about the SOLID principles, but the book really shines once you read past those initial chapters.


For example, here's a great quote from Uncle Bob Martin's PPP, regarding the PROXY pattern:
"It is a way to keep the business rule assets of your project separate from the implementation mechanisms that are currently in vogue." (page 345)
However, this isn't the only way to accomplish this. After reading and understanding the principles in the book, I've found that:
  • By following the D in the SOLID principles (Dependency Inversion Principle), it naturally leads you to design principles such as the PROXY pattern.
  • You have no fear of frameworks polluting your code because the SOLID principles will ensure that the dependencies point in the correct direction
  • Your tests will run extremely fast
  • The only slow tests you have will be integration tests with external resources (database, web services, file system, etc.) and frameworks
  • It's easier to upgrade since you only need to worry about integration failures, not the interaction between business logic and the new framework API. 
If you haven't read the entire book yet, I highly recommend checking it out.  It will change the way you think about writing software forever.

No comments: