Thursday, July 5

Natural Patterns

I read a good RSS about the Presenter Pattern today by Jay Fields. I have Jay on my Reader.

I have used this pattern in the Java world, the old world... Actually, you have to or else you lose focus quick.

I think this can help us all out. In Jay's example he is using the pattern more for saving data and doesn't emphasize enough about how this pattern will pull a ton of logic out of the partials and expose this logic for deeper testing! This is really the strength of the pattern.

I am a huge fan of patterns but I can never remember what patterns are called. Earlier in my career this lead me to steer away from them and focus more on natural patterns. Natural patterns are something I often refer to as Patterns that are just organically grown in your own code base. This is how I think patterns as a whole get extracted out and become formal patterns. However, this can lead to anti-patterns, so you have to be careful.

Back in the "Old World", I used to have one object, my presenter, encapsulate an entire JSP page. At the time of course, this was just a natural pattern that I came up with, who knew it was a presenter! Anyway, this allowed me to pull logic specific to this JSP into the presenter and out of the Servlet, JSP, DAL (Data Access Layer) and wherever. I was also able to inject things I needed for deeper testing.

In the New World, RoR of course, the presenter is equally as important even though we already have this build in structure and testing. I don't think the pattern needs to apply globally here though, just where needed when your controller and view starts getting nasty.

0 comments: