Sunday, February 5, 2012

Design Patterns

Dear Raccoon Lovers!


I just read the software design patterns wiki!


Wikipedia defines a design pattern as just that, a pattern and not a step by step guide of how to solve a problem. It is simply a template to solve a specific problem, with a specific pattern. 


Design patterns are helpful for cleaner code, and they are easier to read for those who have architectural experience. In addition, they help deal with problems that may have not been considered before the implementation by the programmer, but the pattern's designer came up with this pattern after many considerations and through his own experience. 


Patterns are just a micro-architecture design that a programmer should take and adapt to their current work. 


One of my favorite patterns, would be the Builder. 


The Builder pattern is used to separate a complex building into simpler steps. 


The pattern requires 4 things:
A builder (constructs the object step by step)
A concrete builder (builds objects),
A director (someone who guides the way things are built)
A product (something that is returned)




Basically, the builder sets all the paramaters required for construction. 


In java, the Product takes a reference to the ProductBuilder.
Then, the product sets its parameters by calling the ProductBuilder's get parameters. 


The ProductBuilder also has a method Product build(). Which returns a Product object. The build method simply returns Product(this). Where this is a reference to itself, which is how the Product acquires all the parameters. 


PS: I hope this Super Bowl is full of cheddar, potatoes and bacon soup!

No comments:

Post a Comment