Article Preview
Buy Now
FEATURE
Design Patterns Part 4
Using the Facade Pattern
Issue: 22.3 (May/June 2024)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 21,834
Starting Page Number: 52
Article Number: 22304
Resource File(s):
project22304.zip Updated: 2024-05-03 11:26:51
Related Web Link(s):
http://www.xdevmag.com/browse/11.1/11107/
http://www.xdevmag.com/browse/21.4/21405/
http://www.apple.com
Excerpt of article text...
Last year I spoke about Design Patterns at the Xojo conference in London and then wrote about them in
xDev . Recently, I expanded upon that presentation at the MBS Xojo conference in Andernach, Germany, and today I begin a newxDev series covering several more patterns I spoke about there.The first pattern I'll cover is a simple one called a
Facade . The Facade is a structural pattern that helps simplify your access to a more complex API or library. There are many libraries or tool collections available for use with Xojo and other languages, but they are often far more complicated than we need.For example, there's an open source media conversion onsole app called FFmpeg (
https://en.wikipedia.org/wiki/FFmpeg
) that is a common part of popular free apps like VLC and Handbrake. While you can use those GUI apps to convert audio or video to another format, that's also something you might want to do within your own Xojo app. Since FFmpeg runs in the command-line, you can call it in the background and have it work as though it's part of your app.However, FFmpeg has many options that can be overwhelming and make it difficult to work with. Much of the time you just want standard options and for it to do something simple. Creating a facade class that talks to FFmpeg for you and gives you a simple interface with only the options you need, is a great solution.
Another example of this I am more familiar with is the
wkhtmltopdf class (https://wkhtmltopdf.org
), which generates PDF documents from HTML files. I have written about this before inxDev 11.1
and21.4
(seehttp://www.xdevmag.com/browse/11.1/11107/
andhttp://www.xdevmag.com/browse/21.4/21405/
) and it's a great tool, though the command-line interface is exceedingly complicated.Because of that, I wrote my own
wkhClass
class that only offers a subset of wkhtmltopdf's capabilities, but they are generally all you need.
...End of Excerpt. Please purchase the magazine to read the full article.