Introduction When it comes to using creational patterns with PHP, undoubtedly the builder pattern is one of the most understandable, since the logic that stands behind its application is fairly easy to grasp. On the one hand you have a target object, which needs to be programmatically created, while on the other one you count on two objects, called "director" and "builder" respectively, that control the entire creation process. In this situation, the director instructs the builder as to what pieces and parts should be included in the target object, a process that is usually performed by injecting the builder directly into the director's constructor. Of course, this definition can be extended beyond this bunch of buzzwords, and used in the context of a real world application, which helps in understanding how this pattern works. Keeping in mind this practical approach, during the previous article I showed you how to use a few form element objects, along with a form builder class, to create online forms. However, as you'll possibly recall, the implementation of the builder pattern was rather incomplete because the respective form director class remained undefined, a fact that I plan to fix quickly over the course of this last tutorial. As I expressed above, in this article I'll complete the builder pattern, since I'll demonstrate how to define and use a form director class, in this way putting the final strokes on the example that you learned in the previous tutorial. With the preliminaries out of our way, let's find out together how to create a form director class!
blog comments powered by Disqus |