Multimodal code


If your favorite programming language is platform-independent in terms of runtime environment (command line interface, web), you may want to enable your code to run in both environments.

Conceptual approach

Using Dependency Injection, the abstracted runtime environment is injected into the program on its start-up, so the program code itself does not need to be aware of the environment.

Abstraction of runtime environments

What are the aspects that make the difference between runtime environments? Just assign these aspects to variables and let the dependency injector evaluate the runtime environment on starting up the program.


A carriage return linefeed (CRLF) is expressed differently in a web and in a terminal environment. Using a parameter module per runtime environment, the CRLF is assigned to a named variable. Pseudo code:

Terminal environment

variable strCrlf = "\n"

Web environment

variable strCrlf = "<br>"

Starting the program, the dependency injector evaluates the current runtime environment and loads the respective parameter module into memory. Accessing variable “strCrlf”, the program will find the appropriate value.

This way parameters implemented or implementable in both runtime environments are abstracted. Parameters supported by either of the runtime environments (e.g. styles in a web environment) may be conditionally implemented within the program code itself (use with caution as otherwise you may end up with an excessive share of runtime environment specific code in relation to code generating content).


An example of multimodal code is the PHLEX component version overview

Terminal environment

Dualmode code called in terminal

PHLEX version called in terminal

Web environment

PHLEX versions called in web

PHLEX versions called in web

Called in a web environment, styles are loaded in order to adopt a specific look.

In web mode, the web session object is used to store the environment parameters. In terminal mode, an emulated session is created by the dependency injector.

Adjacent use cases

This abstraction concept may also be used for national language support (language parameters are just another category as environment parameters).


English category cloud

Category cloud with English language module


Spanish category cloud

Category cloud with Spanish language module

Leave a comment


Leave a Reply

( Ctrl + Enter )