What is the best wrapping strategy?

I'm planning to integrate an external tool (ffmpeg in my particular case, but it could be anything, in fact, as lolng as its tasks are long running ones). This tool has a lot of command-line parameters.

For now, I've done to simple things with it, already requiring me a good bunch of class writing, to embed all the information it can return to me.

I now face the even more complex task of having to send it a bunch of parameters and to handle possible errors.

So, what is a best way for that ?

  1. Create classes containing all possible options
  2. Relying upon a reverse equivalent of commons-cli / CliBuilder / OptionParser
  3. Directly write all options from user input
  4. Obiwan Kenobi powers (or anything I don't even know about)

Please notice I do it in an uncommon language (for the sake of me, don't ask me what it is, as it looks like a desperate and sterile union between CoffeeScript and lua), as a consequence, there can be no framework doing what I want in the language I use.


I suppose the orthodox answer would be to figure out what domain model the tool embodies, then write some objects which express that model in your language and know how to construct command lines. I don't know ffmpeg well, but i believe the model is sound flowing from a source file to an output file, each in a particular format, through a series of filters. So maybe you have a FfmpegJob class which has two SoundFile objects, one for input and one for output, and a list (which could be empty) of SoundFilter objects. Each subordinate object has a method to turn itself into a sequence of arguments for ffmpeg (eg a HighpassFilter would turn into {"--highpass", "200"} or whatever). The job class can then easily construct a a command line from its subordinates. You do need to write a class per option, but you can lift the common code to a superclass; each subclass should be pretty simple.

This involves more boilerplate than a reverse-optparse approach, but buys you type safety. Also, it gives you a place from where you can start to hang more functionality: you can put validation or calculation in the filter objects, or compose several options into a single more sophisticated filter.

Category: design Time: 2010-12-29 Views: 1
Tags: Design

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.202 (s). 12 q(s)