Custom components

Advanced topic

As mentioned in Simulating objects section FALL makes use of aggregation. This approach reduces dependencies between defined structures, which simplifies the process of implementing custom components.

Table of contents:

What is aggregation?

The simplest practical explanation goes like this: instead of constructing objects inside other objects, we pass them to their constructor:

// aggregation
function classA {

    // return lexicon
}

function classB {
    parameter someObject.

    // return lexicon
}

local A is classA().  // new A object
local B is classB(A). // new B object

rather than:

// composition
function classA {

    // return lexicon
}

function classB {
    local someObject is classA(). // new A object

    // return lexicon
}

local B is classB().  // new B object

Custom component example

landingController is constructed with hoverslamModel object. Let’s assume that you came up with an impressive solution that calculates suicide burn so accurately that FALL hoverslamModel looks like a silly toy.

All you need to know is that hoverslamModel implements only one public method getThrottle.

First write your genius solution in the form of class:

function geniusSuicideBurn {
    // genius custom code

    function getThrottle {
        // returns throttle
    }

    return lexicon(
        // other public methods
        "getThrottle", getThrottle@
      )
}

Now you can construct landingController with your genius solution:

// prep
local ldata is landingDataModel(target:geoposition).
local geniusBurn is geniusSuicideBurn().

local landing is landingController(ldata, geniusBurn).

In this case the landingController uses your custom solution to control the throttle, but keeps its way of steering the rocket.

Simplicity of this approach makes it easier to develop new compatible components. Though it’s worth to mention that lack of type checking and inheritance model can be problematic and that’s exactly why I seriously consider actually implementing OOP layer on top of KOS.