"Sputnik" help  
Sputnik Help
Rule Override If Inherited

Description

This demonstrates how to create a function that overrides any function that tries to replace it when inherited by a class.

Before reading this section make sure to read all User Functions and understand it.

Remarks

The Override If Inherited rule in Sputnik allows you to create a function that overrides any function with the same name in the class that inherits it. This rule ensures that the original function forces itself to override the inherited function, regardless of any attempts to replace it.

In the example provided, there are two classes: "test" and "test2". The "test" class contains a function called "cat" with the "f" flag, indicating that it should override any function with the same name in the inheriting class. The "test2" class inherits from "test" and also contains a function called "cat".

When an instance of the "test2" class is created and the "cat" function is called, the overridden function from the "test" class is executed, printing "meow". Without the Override If Inherited rule, the "cat" function in the "test2" class would replace the one inherited from "test", and "meowey" would be printed instead.

By using the Override If Inherited rule, you can ensure that the original function retains its behavior and overrides any attempts to replace it in the inheriting class. This provides control and consistency when extending classes with custom functions.

Related

User Functions

Example

Bascially what happens here is the original function "cat" prints "meow" however if the class "test" is inherited by "test2" and "test2" contains a function called "cat" it will obviously replace the one its inheriting from "test" however with the "f" flag this makes it so the original function forces itself to override the one in the new class.

class test
{
    "f" function cat()
    {
        say "meow";
    }
}

class test2 inherits "test"
{
    function cat()
    {
        say "meowey";
    }
}

my $cls = new test2();
$cls->cat();

// PRINTS
// meow

Without the override "meowey" would be printed.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org