Using static methods
By definition, a static method is one that could be used without the need to implement the object that contains it. This gives us the option of using entities as containers of grouped methods under certain criteria that the programmer deems appropriate; for example, to create an entity that houses useful methods of unit conversion.
To mark a method as static in Bosque, we will use the static
statement instead of the static
method, as follows:
entity UnitConverter { static poundsToKilograms()(pounds: Float64): Float64 { return pounds * 0.453592; } static milesToKilometers(miles: Float64): Float64 { return miles * 1.60934; } }
As we can see in the previous example, the poundsToKilograms
and milesToKilometers
functions...