Traits is an actively used design pattern. 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.

?Years Old

Languages with Traits include php

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;
}

Last updated August 9th, 2020

Edit Traits on GitHub