The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Managing Code Updates Efficiently - The Facade Pattern
Skill Level: Intermediate-Advanced knowledge in programming; basic understanding of OO structure and concepts in PHP. ** This article may not be reproduced without the owner's (Danny.VBT) permission. Introduction Hypothetically, let's imagine that vBulletin just released version 4.0. They announce that the entire back-end architecture has changed and now you must update your quite large and complex modification to support their new code changes because your users (clients) are demanding functionality for vB 4.0 This definitely means hours of inspecting and altering thousands of lines of code, right? Not if you use implement the Facade pattern! The Facade Pattern? What?s that? The Facade Pattern is a design pattern that introduces a whole lot of benefits when dealing with third party code that you have no control over. In short, it acts as a tier between your modification and vBulletin. Now, you may be asking: But my modification is designed specifically for vBuleltin, why would I want to separate them? Reasons for Utilizing the Facade Pattern
Take the following example: I want to determine if a user has permission to do a certain action. Normally, you would simply have:
If wrapped in a facade class, you would have something like: See how simple that looks? The actual implementation of the permission checking would be in the facade class, but it is only the interface that matters. Now instead of sprinkling vBulletin version specific code throughout your system, you are only providing an interface to that specific implementation.
Let us go back to the previous permission example. Here is the implementation of the permission method:
This class is a simple facade with a permission method to encapsulate the data. Now pretend vBulletin 4.0 is released and the entire permission handling is now altered. Instead of having to go through all the hassle of finding and editing the version specific code throughout your modification, you can simple utilize inheritance to update the methods that need to be altered.
Then at the start of the client code you can determine which class to create: Implementing a Facade Utilizing the facade pattern is not always the best choice. If you are only create a small modification with only a few files or whatnot, it may not be worth the time to design your application around a facade. However, if your modification has more than a handful of files with thousands if not hundred of thousands lines of code, the facade pattern may be a huge time saver for you in the future.
This type of initialization of global variables will most likely be done within the constructor or initialization function.
Implementing a facade would require more than one class, so it important that you fully understand OO before implementing any type of design pattern. Do not just use OO because it seems popular to do.Conclusion I left this article abstract for a reason. I don?t want to provide code to mimic or to copy and paste, but to allow those who unsure or unfamiliar with object oriented programming to see the benefits of OO even with just vBulletin modifications. Take the time to research and understand Object Orientation and it will be extremely beneficial to you in the future. Suggested Readings: PHP 5 Objects, Designs, and Practice by Matt Zandstra; Apress Publishing. The Object Oriented Thought Process by Matt Weisfeld; Sams Publishing. The Pragmatic Programmer by Andrew Hunt and David Thomas. By: Danny Cassidy |
#2
|
||||
|
||||
Quote:
|
#3
|
|||
|
|||
It's hypothetical
|
#4
|
||||
|
||||
Great Article... Thank you Danny!
|
#5
|
|||
|
|||
Ha!
Anyway good tutorial. This a nice practical example of OO. |
#6
|
||||
|
||||
OK. This is a really interesting article.
|
#7
|
|||
|
|||
Very very useful article
Thanks |
#8
|
|||
|
|||
nice idea, so far my mods have been simple, but I'm already spending time changing stuff for 3.7.. I'll consider this in the future!
|
#9
|
|||
|
|||
Yeah, I would only implement this if your modification is pretty extensive....
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|