Content deleted Content added
No edit summary Tags: Mobile edit Mobile web edit |
Citation bot (talk | contribs) Add: website, pages, issue, volume, s2cid. Formatted dashes. | Use this bot. Report bugs. | Suggested by Abductive | #UCB_toolbar |
||
Line 2:
{{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 |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| s2cid=16434119 }}</ref>
==Characteristics==
Line 53:
* [[Haskell (programming language)|Haskell]]: In Haskell, Traits are known as [[Type class]]es.
* [[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 journal | url=https://hal.inria.fr/inria-00432538/ | title= FeatherTrait: A Modest Extension of Featherweight Java | first1=Luigi | last1=Liquori | first2=Arnaud | last2=Spiwack | journal= ACM Transactions on Programming Languages and Systems | date=2008 | volume= 30 | issue= 2 | pages= 11:1 |doi=10.1145/1330017.1330022| s2cid= 17231803 }}</ref><ref>{{cite journal | url=https://hal.inria.fr/inria-00432540/ | title= Extending FeatherTrait Java with Interfaces | first1=Luigi | last1=Liquori | first2=Arnaud | last2=Spiwack | journal= Theoretical Computer Science | date=2008 | volume= 398 | issue= 1–3 | pages= 243–260 |doi=10.1016/j.tcs.2008.01.051| s2cid= 12923128 }}</ref><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>
* [[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 | website=[[GitHub]] | access-date=March 23, 2017}}</ref>
* [[Kotlin (programming language)|Kotlin]]: Traits have been called ''interfaces''<ref>{{cite web | url=http://kotlinlang.org/docs/reference/interfaces.html | title=Interfaces | website=Kotlin Reference | publisher=JetBrains | access-date=January 23, 2016}}</ref> since M12.<ref>{{cite web | url=http://blog.jetbrains.com/kotlin/2015/05/kotlin-m12-is-out/ | title=Kotlin M12 is out! | first=Andrey | last=Breslav | website=Kotlin Blog | publisher=JetBrains | date=May 29, 2015 | access-date=January 23, 2016}}</ref>
* [[Lasso (programming language)|Lasso]]<ref>{{cite web | url=http://lassoguide.com/language/traits.html | title=Traits | website=Lasso Language Guide | publisher=LassoSoft | date=January 6, 2014 | access-date=January 23, 2016}}</ref>
Line 61:
* [[Perl]]: Called ''roles'', they are implemented in Perl libraries such as [[Moose (Perl)|Moose]], Role::Tiny and Role::Basic. Roles are part of the sister language [[Raku (programming language)|Raku]].<ref>{{cite web | url=http://www.modernperlbooks.com/mt/2009/04/the-why-of-perl-roles.html | title=The Why of Perl Roles | author=chromatic | date=April 30, 2009 | access-date=January 23, 2016}}</ref>
* [[PHP]]: Since version 5.4,<ref>{{cite web | url=http://www.php.net/manual/en/language.oop5.traits.php | title=Traits | website=PHP Documentation | publisher=The PHP Group | access-date=January 23, 2016}}</ref><ref name="php:rfc:horizontalreuse">{{cite web | last=Marr | first=Stefan | title=Request for Comments: Horizontal Reuse for PHP | url=https://wiki.php.net/rfc/horizontalreuse | website=PHP.net wiki | publisher=The PHP Group | date=January 9, 2011 | access-date=January 31, 2011}}</ref> PHP allows users to specify templates that provide the ability to "inherit" from more than one (trait-)class, as a pseudo [[multiple inheritance]].
* [[Python (programming language)|Python]]: Via a third-party library,<ref>{{cite web | url=http://py3traits.readthedocs.org/ | title=py3traits Documentation | first=Teppo | last=Perä | access-date=January 23, 2016}}</ref><ref>{{cite web | url=https://github.com/Debith/py2traits | title=py2traits | first=Teppo | last=Perä | website=[[GitHub]] | access-date=January 23, 2016| date=2015-03-25 }}</ref> or via higher-order mixin classes<ref>{{cite web | url=http://stupid-python-tricks.blogspot.com/2015/04/computed-properties-and-higher-order.html | title = Higher Order Mixin Classes | archive-date = 2016-10-09 | archive-url = https://web.archive.org/web/20161009062141/http://stupid-python-tricks.blogspot.com/2015/04/computed-properties-and-higher-order.html }}</ref>
* [[Racket (programming language)|Racket]]: Supports traits as a library and uses macros, structures, and first-class classes to implement them.<ref>{{cite web | url=http://docs.racket-lang.org/reference/trait.html | title=Traits | website=The Racket Reference | access-date=January 23, 2016}}</ref>
* [[Ruby (programming language)|Ruby]]: ''Module mixins'' can be used to implement traits.<ref>{{cite web | url=http://ruby-naseby.blogspot.com/2008/11/traits-in-ruby.html | title=Traits in Ruby | website=Ruby Naseby | author=David Naseby | date=February 14, 2004 | access-date=January 23, 2016}}</ref>
|