new_class {bandicoot}R Documentation

Define a new class

Description

This function declare a new class, and copies attributes and methods from parent classes.

Usage

new_class(
  ...,
  env = new.env(parent = parent.frame()),
  class_name = NULL,
  empty_class = FALSE
)

Arguments

...

Environments. Parent class environments.

env

Environment. The new class environment.

class_name

Name of the new class.

empty_class

Boolean. Whether to create an empty class. This should only be used when you don't want to inherited from BASE, or you want to define your own base object class. Will be ignored if ... is not empty. If ... is empty and empty_class == FALSE, BASE will be used as the parent class.

Details

Parents can be provided in ..., where methods and attributes will be overrided by the left classes because bandicoot does not support dynamic dispatch at the moment. However, this behaviour usually aligns with the method resolution order defined by the C3 algorithm used in Python. If ... is empty and empty_class == FALSE, BASE will be used as the parent class.

Value

A class environment with S3 class "bandicoot_oop".

Examples

MYCLASS <- new_class(class_name = "MYCLASS")
MYCLASS
names(MYCLASS)

# Inhert from BASE class
TEST <- new_class(BASE, class_name = "TEST")
TEST
names(TEST)


[Package bandicoot version 1.0.0 Index]