Trait (computer programming): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m linking
Tweak cites
Line 1: Line 1:
{{Technical|date=March 2012}}
{{Technical|date=March 2012}}


In [[computer programming]], a '''trait''' is a concept used in [[object-oriented programming]], which represents a set of [[Method (computer programming)|methods]] that can be used to extend the functionality of a [[Class (computer science)|class]].<ref name="schaerli-ecoop-2003">{{cite journal | first1=Nathanael | last1=Schärli | first2=Stéphane | last2=Ducasse | first3=Oscar | last3=Nierstrasz | author-link3=Oscar Nierstrasz | first4=Andrew P. | last4=Black | url=http://scg.unibe.ch/archive/papers/Scha03aTraits.pdf | title=Traits: Composable Units of Behaviour | journal=Proceedings of the European Conference on Object-Oriented Programming (ECOOP). | series=Lecture Notes in Computer Science | volume=2743 | year=2003 | pages=248–274}}</ref><ref>{{cite journal | first1=Stéphane | last1=Ducasse | first2=Oscar | last2=Nierstrasz | first3=Nathanael | last3=Schärli | first4=Roel | last4=Wuyts | first5=Andrew P. | last5=Black | title=Traits: A mechanism for fine-grained reuse. | journal= ACM Transactions on Programming Languages and Systems | volume=28 | issue=2 | pages=331–388 | date=March 2006 | doi=10.1145/1119479.1119483}}</ref>
In [[computer programming]], a '''trait''' is a concept used in [[object-oriented programming]], which represents a set of [[Method (computer programming)|methods]] that can be used to extend the functionality of a [[Class (computer science)|class]].<ref name="schaerli-ecoop-2003">{{cite journal | first1=Nathanael | last1=Schärli | first2=Stéphane | last2=Ducasse | first3=Oscar | last3=Nierstrasz | author-link3=Oscar Nierstrasz | first4=Andrew P. | last4=Black | url=http://scg.unibe.ch/archive/papers/Scha03aTraits.pdf | title=Traits: Composable Units of Behaviour | journal=Proceedings of the European Conference on Object-Oriented Programming (ECOOP). | series=Lecture Notes in Computer Science | volume=2743 | year=2003 | pages=248–274 |publisher=Springer |doi=10.1007/978-3-540-45070-2_12 |isbn=978-3-540-45070-2 |citeseerx=10.1.1.1011.8}}</ref><ref>{{cite journal | first1=Stéphane | last1=Ducasse | first2=Oscar | last2=Nierstrasz | first3=Nathanael | last3=Schärli | first4=Roel | last4=Wuyts | first5=Andrew P. | last5=Black | title=Traits: A mechanism for fine-grained reuse. | journal= ACM Transactions on Programming Languages and Systems | volume=28 | issue=2 | pages=331–388 | date=March 2006 | doi=10.1145/1119479.1119483 |citeseerx=10.1.1.64.2480}}</ref>


==Characteristics==
==Characteristics==
Line 43: Line 43:
Traits come originally from the programming language [[Self (programming language)|Self]]<ref>{{cite conference | first1=Gael | last1=Curry | first2=Larry | last2=Baer | first3=Daniel | last3=Lipkie | first4=Bruce | last4=Lee | title=Traits: An approach to multiple-inheritance subclassing | conference=SIGOA Conference on Office Information Systems | pages=1–9 | location=Philadelphia, Pennsylvania, USA | year=1982 | publisher=ACM Press | doi=10.1145/966873.806468 }}</ref> and are supported by the following programming languages:
Traits come originally from the programming language [[Self (programming language)|Self]]<ref>{{cite conference | first1=Gael | last1=Curry | first2=Larry | last2=Baer | first3=Daniel | last3=Lipkie | first4=Bruce | last4=Lee | title=Traits: An approach to multiple-inheritance subclassing | conference=SIGOA Conference on Office Information Systems | pages=1–9 | location=Philadelphia, Pennsylvania, USA | year=1982 | publisher=ACM Press | doi=10.1145/966873.806468 }}</ref> and are supported by the following programming languages:


* [[AmbientTalk]]: Combines the properties of Self traits (object-based multiple inheritance) and [[Smalltalk]]'s [[Squeak]] traits (requiring explicit composition of traits by the programmer). It builds on the research on ''stateful'' and ''freezable'' traits to enable state within traits, which was not allowed in the first definitions.<ref>{{cite conference | url=http://soft.vub.ac.be/Publications/2009/vub-prog-tr-09-04.pdf | title=Adding State and Visibility Control to Traits Using Lexical Nesting | conference=European Conference on Object-Oriented Programming (ECOOP 2009) | first1=Tom | last1=Van Cutsem | first2=Alexandre | last2=Bergel | first3=Stéphane | last3=Ducasse | first4=Wolfgang | last4=De Meuter | pages=220–243 | publisher=Springer-Verlag | isbn=978-3-642-03012-3 | date=2009 | series=Lecture Notes in Computer Science | volume=5653 |doi=10.1007/978-3-642-03013-0_11}}</ref>
* [[AmbientTalk]]: Combines the properties of Self traits (object-based multiple inheritance) and [[Smalltalk]]'s [[Squeak]] traits (requiring explicit composition of traits by the programmer). It builds on the research on ''stateful'' and ''freezable'' traits to enable state within traits, which was not allowed in the first definitions.<ref>{{cite conference | url=http://soft.vub.ac.be/Publications/2009/vub-prog-tr-09-04.pdf | title=Adding State and Visibility Control to Traits Using Lexical Nesting | conference=European Conference on Object-Oriented Programming (ECOOP 2009) | first1=Tom | last1=Van Cutsem | first2=Alexandre | last2=Bergel | first3=Stéphane | last3=Ducasse | first4=Wolfgang | last4=De Meuter | pages=220–243 | publisher=Springer-Verlag | isbn=978-3-642-03012-3 | date=2009 | series=Lecture Notes in Computer Science | volume=5653 |doi=10.1007/978-3-642-03013-0_11 |citeseerx=10.1.1.372.1265}}</ref>
*[[C Sharp (programming language)|C#]]: Since version 8.0, C# has support for ''default interface methods'',<ref>{{cite web | url=https://docs.microsoft.com/en-gb/dotnet/csharp/whats-new/csharp-8#default-interface-methods | title=Default interface methods | website=What's new in C# 8.0 | publisher=Microsoft | access-date=November 29, 2019}}</ref> which have some properties of traits.<ref>{{cite web | url=https://www.talkingdotnet.com/default-implementations-in-interfaces-in-c-sharp-8/ | title=Interfaces in C# 8.0 gets a makeover | website=Default Implementation in Interfaces in C# 8.0 | publisher=Talking Dotnet | access-date=November 29, 2019}}</ref>
*[[C Sharp (programming language)|C#]]: Since version 8.0, C# has support for ''default interface methods'',<ref>{{cite web | url=https://docs.microsoft.com/en-gb/dotnet/csharp/whats-new/csharp-8#default-interface-methods | title=Default interface methods | website=What's new in C# 8.0 | publisher=Microsoft | access-date=November 29, 2019}}</ref> which have some properties of traits.<ref>{{cite web | url=https://www.talkingdotnet.com/default-implementations-in-interfaces-in-c-sharp-8/ | title=Interfaces in C# 8.0 gets a makeover | website=Default Implementation in Interfaces in C# 8.0 | publisher=Talking Dotnet | access-date=November 29, 2019}}</ref>
* [[C++]]: Used in [[Standard Template Library]] and the [[C++ standard library]] to support generic [[Container (data structure)|container classes]]<ref>{{cite web | url=http://www.sgi.com/tech/stl/iterator_traits.html | title=iterator_traits&lt;Iterator&gt; | website=Standard Template Library | publisher=SGI}}</ref><ref>{{cite magazine | url=http://www.cantrip.org/traits.html | title=Traits: a new and useful template technique | first=Nathan C. | last=Myers | magazine=C++ Report | date=June 1995 | access-date=January 23, 2016}}</ref> and in the [[Boost C++ Libraries|Boost]] TypeTraits library.<ref>{{cite web | url=http://www.boost.org/more/generic_programming.html#traits | title=Generic Programming Techniques: Traits | website=Boost C++ Libraries | first=David | last=Abrahams | access-date=January 23, 2016}}</ref>
* [[C++]]: Used in [[Standard Template Library]] and the [[C++ standard library]] to support generic [[Container (data structure)|container classes]]<ref>{{cite web | url=http://www.sgi.com/tech/stl/iterator_traits.html | title=iterator_traits&lt;Iterator&gt; | website=Standard Template Library | publisher=SGI}}</ref><ref>{{cite magazine | url=http://www.cantrip.org/traits.html | title=Traits: a new and useful template technique | first=Nathan C. | last=Myers | magazine=C++ Report | date=June 1995 | access-date=January 23, 2016}}</ref> and in the [[Boost C++ Libraries|Boost]] TypeTraits library.<ref>{{cite web | url=http://www.boost.org/more/generic_programming.html#traits | title=Generic Programming Techniques: Traits | website=Boost C++ Libraries | first=David | last=Abrahams | access-date=January 23, 2016}}</ref>
Line 52: Line 52:
* [[Haskell (programming language)|Haskell]]: In Haskell, Traits are known as [[Type class|Type classes]].
* [[Haskell (programming language)|Haskell]]: In Haskell, Traits are known as [[Type class|Type classes]].
* [[Haxe]]: Since version 2.4.0.<ref>{{Cite news|url=https://haxe.org/download/version/2.4.0/|title=Haxe 2.4.0 - Haxe - The Cross-platform Toolkit|work=Haxe - The Cross-platform Toolkit|access-date=2017-09-12}}</ref> Called ''Static Extension''<ref>{{Cite news|url=https://haxe.org/manual/lf-static-extension.html|title=Manual - Haxe - The Cross-platform Toolkit|work=Haxe - The Cross-platform Toolkit|access-date=2017-09-12}}</ref> in the manual, it uses <code>using</code> keyword
* [[Haxe]]: Since version 2.4.0.<ref>{{Cite news|url=https://haxe.org/download/version/2.4.0/|title=Haxe 2.4.0 - Haxe - The Cross-platform Toolkit|work=Haxe - The Cross-platform Toolkit|access-date=2017-09-12}}</ref> Called ''Static Extension''<ref>{{Cite news|url=https://haxe.org/manual/lf-static-extension.html|title=Manual - Haxe - The Cross-platform Toolkit|work=Haxe - The Cross-platform Toolkit|access-date=2017-09-12}}</ref> in the manual, it uses <code>using</code> keyword
* [[Java (programming language)|Java]]: Since version 8, Java has support for ''default methods'',<ref>{{cite web | url=https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html | title=Default Methods | website=The Java Tutorials | publisher=Oracle | access-date=January 23, 2016}}</ref> which have some properties of traits.<ref>{{cite conference | url=https://hal.inria.fr/hal-01026531/en | title=Trait-oriented Programming in Java 8 | first1=Viviana | last1=Bono | first2=Enrico | last2=Mensa | first3=Marco | last3=Naddeo | conference=International Conference on Principles and Practices of Programming on the Java Platform: virtual machines, languages, and tools (PPPJ ’14) | date=September 2014 | location=Kraków, Poland | conference-url=http://pppj2014.pk.edu.pl/}}</ref><ref>{{cite web | title=Definition of the Trait Pattern in Java | url=http://ageofjava.com/2016/02/definition-of-trait-pattern-in-java.html | archive-url=https://web.archive.org/web/20160804005218/http://ageofjava.com/2016/02/definition-of-trait-pattern-in-java.html | url-status=dead | archive-date=August 4, 2016 | website=Age of Java | date=February 3, 2016 | access-date=February 3, 2016 | first=Emil | last=Forslund}}</ref>
* [[Java (programming language)|Java]]: Since version 8, Java has support for ''default methods'',<ref>{{cite web | url=https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html | title=Default Methods | website=The Java Tutorials | publisher=Oracle | access-date=January 23, 2016}}</ref> which have some properties of traits.<ref>{{cite conference | url=https://hal.inria.fr/hal-01026531/en | title=Trait-oriented Programming in Java 8 | first1=Viviana | last1=Bono | first2=Enrico | last2=Mensa | first3=Marco | last3=Naddeo | conference=International Conference on Principles and Practices of Programming on the Java Platform: virtual machines, languages, and tools (PPPJ ’14) | date=September 2014 | conference-url=http://pppj2014.pk.edu.pl/ |pages=181–6 |doi=10.1145/2647508.2647520 |citeseerx=10.1.1.902.161}}</ref><ref>{{cite web | title=Definition of the Trait Pattern in Java | url=http://ageofjava.com/2016/02/definition-of-trait-pattern-in-java.html | archive-url=https://web.archive.org/web/20160804005218/http://ageofjava.com/2016/02/definition-of-trait-pattern-in-java.html | url-status=dead | archive-date=August 4, 2016 | website=Age of Java | date=February 3, 2016 | access-date=February 3, 2016 | first=Emil | last=Forslund}}</ref>
* [[JavaScript]]: Traits can be implemented via functions and delegations<ref>{{cite web | url=http://peterseliger.blogspot.com/2014/04/the-many-talents-of-javascript.html | title=The Many Talents of JavaScript | first=Peter | last=Seliger | date=April 11, 2014 | access-date=January 23, 2015}}</ref> or through libraries that provide traits.<ref>{{cite web | url=https://traitsjs.github.io/traits.js-website/ | title=Traits.js: Traits for JavaScript | access-date=January 23, 2016}}</ref><ref>{{cite journal | url=http://soft.vub.ac.be/Publications/2012/vub-soft-tr-12-19.pdf | title=Robust Trait Composition for Javascript | first1=Tom | last1=Van Cutsem | first2=Mark S. | last2=Miller | journal=Science of Computer Programming| year=2012 | access-date=January 23, 2016}}</ref><ref>{{cite web | url=https://cocktailjs.github.io/ | title=CocktailJS | access-date=January 23, 2016}}</ref>
* [[JavaScript]]: Traits can be implemented via functions and delegations<ref>{{cite web | url=http://peterseliger.blogspot.com/2014/04/the-many-talents-of-javascript.html | title=The Many Talents of JavaScript | first=Peter | last=Seliger | date=April 11, 2014 | access-date=January 23, 2015}}</ref> or through libraries that provide traits.<ref>{{cite web | url=https://traitsjs.github.io/traits.js-website/ | title=Traits.js: Traits for JavaScript | access-date=January 23, 2016}}</ref><ref>{{cite journal | url=http://soft.vub.ac.be/Publications/2012/vub-soft-tr-12-19.pdf | title=Robust Trait Composition for Javascript | first1=Tom | last1=Van Cutsem | first2=Mark S. | last2=Miller | journal=Science of Computer Programming| year=2012 | access-date=January 23, 2016}}</ref><ref>{{cite web | url=https://cocktailjs.github.io/ | title=CocktailJS | access-date=January 23, 2016}}</ref>
* [[Julia (programming language)|Julia]]: Several packages implement traits, e.g.,<ref>{{cite web | url=https://github.com/mauro3/SimpleTraits.jl | title=SimpleTraits.jl | author=mauro3 | access-date=March 23, 2017}}</ref>
* [[Julia (programming language)|Julia]]: Several packages implement traits, e.g.,<ref>{{cite web | url=https://github.com/mauro3/SimpleTraits.jl | title=SimpleTraits.jl | author=mauro3 | access-date=March 23, 2017}}</ref>

Revision as of 22:27, 13 October 2021

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.[1][2]

Characteristics

Traits both provide a set of methods that implement behaviour to a class, and require that the class implement a set of methods that parameterize the provided behaviour.

For inter-object communication, traits are somewhere between an object-oriented protocol (interface) and a mixin. An interface may define one or more behaviors via method signatures, while a trait defines behaviors via full method definitions: i.e., it includes the body of the methods. In contrast, mixins include full method definitions and may also carry state through member variable, while traits usually don't.

Hence an object defined as a trait is created as the composition of methods, which can be used by other classes without requiring multiple inheritance. In case of a naming collision, when more than one trait to be used by a class has a method with the same name, the programmer must explicitly disambiguate which one of those methods will be used in the class; thus manually solving the diamond problem of multiple inheritance. This is different from other composition methods in object-oriented programming, where conflicting names are automatically resolved by scoping rules.

Whereas mixins can be composed only using the inheritance operation, traits offer a much wider selection of operations, including:[3][4]

  • symmetric sum: an operation that merges two disjoint traits to create a new trait
  • override (or asymmetric sum): an operation that forms a new trait by adding methods to an existing trait, possibly overriding some of its methods
  • alias: an operation that creates a new trait by adding a new name for an existing method
  • exclusion: an operation that forms a new trait by removing a method from an existing trait. (Combining this with the alias operation yields a shallow rename operation).

Traits are composed in the following ways:

  • Trait composition is commutative; the ordering of adding traits does not matter. For example, given trait S = A + B, then trait T = B + A is the same as S.
  • Conflicting methods are excluded from the composition.
  • Nested traits are equivalent to flattened traits; the composition hierarchy does not affect the traits behaviour. For example, given trait S = A + X, where X = B + C, then trait T = A + B + C is the same as S.[1]

Supported languages

Traits come originally from the programming language Self[5] and are supported by the following programming languages:

  • AmbientTalk: Combines the properties of Self traits (object-based multiple inheritance) and Smalltalk's Squeak traits (requiring explicit composition of traits by the programmer). It builds on the research on stateful and freezable traits to enable state within traits, which was not allowed in the first definitions.[6]
  • C#: Since version 8.0, C# has support for default interface methods,[7] which have some properties of traits.[8]
  • C++: Used in Standard Template Library and the C++ standard library to support generic container classes[9][10] and in the Boost TypeTraits library.[11]
  • Curl: Abstract classes as mixins permit method implementations and thus constitute traits by another name.[citation needed]
  • D: Since version 2.003, the __traits language extension[12] and std.traits module[13] helper templates provide compile-time traits. Together with other language features (notably templates and mixins), they allow flexible automatic generation of methods based on interfaces and types. D also allows explicit aliasing of member methods and variables, including forwarding to multiple member classes.[14]
  • Fortress[15]
  • Groovy: Since version 2.3[16]
  • Haskell: In Haskell, Traits are known as Type classes.
  • Haxe: Since version 2.4.0.[17] Called Static Extension[18] in the manual, it uses using keyword
  • Java: Since version 8, Java has support for default methods,[19] which have some properties of traits.[20][21]
  • JavaScript: Traits can be implemented via functions and delegations[22] or through libraries that provide traits.[23][24][25]
  • Julia: Several packages implement traits, e.g.,[26]
  • Kotlin: Traits have been called interfaces[27] since M12.[28]
  • Lasso[29]
  • OCaml: Traits can be implemented using a variety of language features: module and module type inclusion, functors and functor types, class and class type inheritance, et cetera.
  • Perl: Called roles, they are implemented in Perl libraries such as Moose, Role::Tiny and Role::Basic. Roles are part of the sister language Raku.[30]
  • PHP: Since version 5.4,[31][32] PHP allows users to specify templates that provide the ability to "inherit" from more than one (trait-)class, as a pseudo multiple inheritance.
  • Python: Via a third-party library,[33][34] or via higher-order mixin classes[35]
  • Racket: Supports traits as a library and uses macros, structures, and first-class classes to implement them.[36]
  • Ruby: Module mixins can be used to implement traits.[37]
  • Rust[38]
  • Scala[39][40] trait is builtin supported with the key word trait.
  • Smalltalk: Traits are implemented in two dialects of Smalltalk, Squeak[1] and Pharo.[41]
  • Swift: Traits can be implemented with protocol extensions.[42]

Examples

C#

On C# 8.0, it is possible to define an implementation as a member of an interface.

using System;

namespace CSharp8NewFeatures
{
    interface ILogger
    {
        // Traditional interface methods
        void Log(string message);
        void LogError(Exception exception);

        // Default interface method
        void LogWarning(string message)
        {
            Console.WriteLine(message);
        }        
    }

    class Logger : ILogger
    {
        public void Log(string message)
        {
            Console.WriteLine(message);
        }

        public void LogError(Exception exception)
        {
            Console.WriteLine(exception.ToString());
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ILogger logger = new Logger();

            logger.LogWarning("Some warning message");
        }
    }
}

PHP

This example uses a trait to enhance other classes:

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

This allows simulating aspects of multiple inheritance:

trait TBounding
{
    public $x, $y, $width, $height;
}

trait TMoveable
{
    public function moveTo($x, $y)
    {
        // …
    }
}

trait TResizeable
{
    public function resize($newWidth, $newHeight)
    {
        // …
    }
}

class Rectangle
{
    use TBounding, TMoveable, TResizeable;

    public function fillColor($color)
    {
        // …
    }
}

Rust

A trait in Rust declares a set of methods that a type must implement.[43] Rust compilers require traits to be explicated, which ensures the safety of generics in Rust.

// type T must have the "Ord" trait
// so that ">" and "<" operations can be done
fn get_max<T: Ord>(a: &[T]) -> Option<&T> {
    let mut result = a.get(0)?;
    for n in a {
        if *n > *result {
            result = &n;
        }
    }
    Some(result)
}

To simplify tedious and repeated implementation of traits like Debug and Ord, the derive macro can be used to request compilers to generate certain implementations automatically.[44] Derivable traits include: Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord and Hash.

See also

References

  1. ^ a b c Schärli, Nathanael; Ducasse, Stéphane; Nierstrasz, Oscar; Black, Andrew P. (2003). "Traits: Composable Units of Behaviour" (PDF). Proceedings of the European Conference on Object-Oriented Programming (ECOOP). Lecture Notes in Computer Science. 2743. Springer: 248–274. CiteSeerX 10.1.1.1011.8. doi:10.1007/978-3-540-45070-2_12. ISBN 978-3-540-45070-2.
  2. ^ Ducasse, Stéphane; Nierstrasz, Oscar; Schärli, Nathanael; Wuyts, Roel; Black, Andrew P. (March 2006). "Traits: A mechanism for fine-grained reuse". ACM Transactions on Programming Languages and Systems. 28 (2): 331–388. CiteSeerX 10.1.1.64.2480. doi:10.1145/1119479.1119483.
  3. ^ Fisher, Kathleen; Reppy, John (2003). "Statically typed traits" (PDF). University of Chicago. Archived (PDF) from the original on May 17, 2004. {{cite journal}}: Cite journal requires |journal= (help)
  4. ^ Fisher, Kathleen; Reppy, John (2004). A typed calculus of traits (PDF). 11th Workshop on Foundations of Object-oriented Programming. University of Chicago.
  5. ^ Curry, Gael; Baer, Larry; Lipkie, Daniel; Lee, Bruce (1982). Traits: An approach to multiple-inheritance subclassing. SIGOA Conference on Office Information Systems. Philadelphia, Pennsylvania, USA: ACM Press. pp. 1–9. doi:10.1145/966873.806468.
  6. ^ Van Cutsem, Tom; Bergel, Alexandre; Ducasse, Stéphane; De Meuter, Wolfgang (2009). Adding State and Visibility Control to Traits Using Lexical Nesting (PDF). European Conference on Object-Oriented Programming (ECOOP 2009). Lecture Notes in Computer Science. Vol. 5653. Springer-Verlag. pp. 220–243. CiteSeerX 10.1.1.372.1265. doi:10.1007/978-3-642-03013-0_11. ISBN 978-3-642-03012-3.
  7. ^ "Default interface methods". What's new in C# 8.0. Microsoft. Retrieved November 29, 2019.
  8. ^ "Interfaces in C# 8.0 gets a makeover". Default Implementation in Interfaces in C# 8.0. Talking Dotnet. Retrieved November 29, 2019.
  9. ^ "iterator_traits<Iterator>". Standard Template Library. SGI.
  10. ^ Myers, Nathan C. (June 1995). "Traits: a new and useful template technique". C++ Report. Retrieved January 23, 2016.
  11. ^ Abrahams, David. "Generic Programming Techniques: Traits". Boost C++ Libraries. Retrieved January 23, 2016.
  12. ^ "Traits". The D Language Reference. Digital Mars. Retrieved January 23, 2016.
  13. ^ "std.traits". The D Language — Library Reference. Digital Mars. Retrieved January 23, 2016.
  14. ^ "Classes". The D Language Reference. Digital Mars. Retrieved January 23, 2016.
  15. ^ Steele, Guy; Maessen, Jan-Willem (June 11, 2006). "Fortress Programming Language Tutorial" (PDF). Sun Microsystems. Retrieved January 23, 2016.
  16. ^ "Object Orientation: Traits". The Groovy Programming Language. Retrieved January 23, 2016.
  17. ^ "Haxe 2.4.0 - Haxe - The Cross-platform Toolkit". Haxe - The Cross-platform Toolkit. Retrieved 2017-09-12.
  18. ^ "Manual - Haxe - The Cross-platform Toolkit". Haxe - The Cross-platform Toolkit. Retrieved 2017-09-12.
  19. ^ "Default Methods". The Java Tutorials. Oracle. Retrieved January 23, 2016.
  20. ^ Bono, Viviana; Mensa, Enrico; Naddeo, Marco (September 2014). Trait-oriented Programming in Java 8. International Conference on Principles and Practices of Programming on the Java Platform: virtual machines, languages, and tools (PPPJ ’14). pp. 181–6. CiteSeerX 10.1.1.902.161. doi:10.1145/2647508.2647520.
  21. ^ Forslund, Emil (February 3, 2016). "Definition of the Trait Pattern in Java". Age of Java. Archived from the original on August 4, 2016. Retrieved February 3, 2016.
  22. ^ Seliger, Peter (April 11, 2014). "The Many Talents of JavaScript". Retrieved January 23, 2015.
  23. ^ "Traits.js: Traits for JavaScript". Retrieved January 23, 2016.
  24. ^ Van Cutsem, Tom; Miller, Mark S. (2012). "Robust Trait Composition for Javascript" (PDF). Science of Computer Programming. Retrieved January 23, 2016.
  25. ^ "CocktailJS". Retrieved January 23, 2016.
  26. ^ mauro3. "SimpleTraits.jl". Retrieved March 23, 2017.{{cite web}}: CS1 maint: numeric names: authors list (link)
  27. ^ "Interfaces". Kotlin Reference. JetBrains. Retrieved January 23, 2016.
  28. ^ Breslav, Andrey (May 29, 2015). "Kotlin M12 is out!". Kotlin Blog. JetBrains. Retrieved January 23, 2016.
  29. ^ "Traits". Lasso Language Guide. LassoSoft. January 6, 2014. Retrieved January 23, 2016.
  30. ^ chromatic (April 30, 2009). "The Why of Perl Roles". Retrieved January 23, 2016.
  31. ^ "Traits". PHP Documentation. The PHP Group. Retrieved January 23, 2016.
  32. ^ Marr, Stefan (January 9, 2011). "Request for Comments: Horizontal Reuse for PHP". PHP.net wiki. The PHP Group. Retrieved January 31, 2011.
  33. ^ Perä, Teppo. "py3traits Documentation". Retrieved January 23, 2016.
  34. ^ Perä, Teppo (2015-03-25). "py2traits". Retrieved January 23, 2016.
  35. ^ "Higher Order Mixin Classes". Archived from the original on 2016-10-09.
  36. ^ "Traits". The Racket Reference. Retrieved January 23, 2016.
  37. ^ David Naseby (February 14, 2004). "Traits in Ruby". Ruby Naseby. Retrieved January 23, 2016.
  38. ^ "Traits". The Rust Programming Language. Retrieved September 30, 2019.
  39. ^ "Traits". A Tour of Scala. École polytechnique fédérale de Lausanne. Retrieved January 23, 2016.
  40. ^ Neward, Ted (April 29, 2008). "The busy Java developer's guide to Scala: Of traits and behaviors". IBM developerWorks. IBM. Retrieved January 23, 2016.
  41. ^ "Traits in 10 minutes". Pharo: The CollaborActive Book. Retrieved January 23, 2016.
  42. ^ Hollemans, Matthijs (July 22, 2015). "Mixins and Traits in Swift 2.0". Retrieved January 23, 2016.
  43. ^ "Traits - Introduction to Programming Using Rust".
  44. ^ "Traits - the Rust Programming Language".

External links