"Sputnik" help  
Sputnik Help
Rule Override Abstract

Description

This demonstrates how to create a function overrides an abstract function.

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

Remarks

The Override Abstract rule in Sputnik allows you to create a function that overrides an abstract function defined in a parent class. Abstract functions are barebones functions that are required to be inherited and overridden in order to ensure that classes follow strict rules on the functions they must implement.

In the example provided, there are two classes: "Test" and "Test2". The "Test" class contains an abstract function called "Cat" defined with the "a" flag. The "Test2" class inherits from "Test" and overrides the "Cat" function using the "ao" flag, which signifies that it is an override for an abstract function.

When an instance of the "Test2" class is created and the "Cat" function is called, the overridden function in the "Test2" class is executed, printing "Meow!". The override ensures that the abstract function in the parent class is implemented and provides the desired functionality in the inheriting class.

By using the Override Abstract rule, you can enforce the presence of specific functions in classes and ensure that they are properly overridden when inherited. This helps maintain consistency and adherence to the defined class structure.

Related

User Functions
Abstract Functions

Example

In this example a class called "Test" is created that has an abstract function then a class called "Test2" is created that inherits the class "Test" since both classes contain a function called "Cat" and that function is abstract "Test" must override it in order it successfully implement the function in question.

This is used to ensure classes that inherit absolutely do have a function by that name and makes it so the class maker knows if the original function ever disappears since an error will trigger.

Class Test
{
    "a" Function Cat() { }
}

Class Test2 inherits 'Test'
{
    "ao" Function Cat()
    {
        say "Meow!";
    }
}

$a = new Test2();
$a->Cat();

// PRINTS
// Meow!

This is how to override abstract functions.


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