Skip to main content

Abstract module

Abstract modules and functions allow you to design reusable code components that you can adapt to specific needs within your client modules.

Definition

  • Abstract Modules: Lay the foundation for customization by declaring a module as abstract:

    abstract module;
  • Abstract Functions: Outline a function's signature without implementing its body:

    abstract function customize(x: integer): text;

    It is also possible to supply an implementation that will serve as a default implementation:

    abstract function customize(x: integer): text = "Default";

Override for customization

  • Import the Abstract Module: Bring the abstract module into your client module to access its components:

    import lib;
    note

    When importing an abstract module, it's crucial to override all its abstract functions that lack a body to ensure a fully functional implementation.

  • Override Abstract Functions: Provide concrete implementations tailored to your specific requirements:

    override function lib.customize(x: integer): text {
    // Your customized implementation here
    }

Example

abstract_vehicle.rell
abstract module;

abstract function is_4wd(): boolean = false;
abstract function has_four_doors(): boolean;
sportscar.rell
module;

import abstract_vehicle.*;

override function has_four_doors() = false;
main.rell
module;

import sportscar;

// Returns (is_4wd = true, has_four_doors = false)
query sports_car_details() = (
is_4wd = sportscar.is_4wd(),
has_four_doors = sportscar.has_four_doors()
);