PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Traits

Traits

Traits are a feature.

Sometimes referred to as mixins. In computer programming, a trait is a concept used in object-oriented programming, which represents a set of methods that can be used to extend the functionality of a class.


Languages with Traits include PHP, Jule

Example from PHP:
// The template trait TSingleton { private static $_instance = null; private function __construct(){} // Must have private default constructor and be aware not to open it in the class public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } } class FrontController { use TSingleton; } // Can also be used in already extended classes class WebSite extends SomeClass { use TSingleton; }
Example from Jule:
trait Person { fn full_name(self) str fn age() byte }
threads-feature.html 路 traits-feature.html 路 triple-feature.html

View source

PLDB - Build the next great programming language 路 v2022 Day 33 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub feedback@pldb.com