Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 22.3

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):

Download Icon 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 new xDev 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 in xDev 11.1 and 21.4 (see http://www.xdevmag.com/browse/11.1/11107/ and http://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.