翻訳と辞書
Words near each other
・ Trairi River (Rio Grande do Norte)
・ Trairong Suwankiri
・ Trairão
・ Trairão River
・ Trairūpya
・ Traisen
・ Traisen (river)
・ Traisen, Austria
・ Traisen, Germany
・ Traiskirchen
・ Traiskirchen Lions
・ Traismauer
・ Traisy Vivien Tukiet
・ Trait
・ Trait (album)
Trait (computer programming)
・ Trait Activation Theory
・ Trait ascription bias
・ Trait d'Union
・ Trait du Nord
・ Trait leadership
・ Trait pour trait
・ Trait theory
・ Traita
・ Traiteur
・ Traiteur (culinary profession)
・ Traiteur (disambiguation)
・ Traitiéfontaine
・ Traitor (Captain Scarlet)
・ Traitor (disambiguation)


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Trait (computer programming) : ウィキペディア英語版
Trait (computer programming)

In computer programming, a trait is a concept used in object-oriented programming: a trait represents a collection of methods that can be used to extend the functionality of a class.
Essentially a trait is similar to a class made only of concrete methods that is used to extend another class with a mechanism similar to multiple inheritance, but paying attention to name conflicts, hence with some support from the language for a name-conflict resolution policy to use when merging.
Traits provide a "simple conceptual model for structuring object-oriented programs"〔Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, Andrew P. Black. (Traits: Composable Units of Behaviour ). Proceedings of the European Conference on Object-Oriented Programming (ECOOP). ''Lecture Notes in Computer Science'', Volume 2743, Springer-Verlag, 2003, pp. 248-274〕〔Stéphane Ducasse, Oscar Nierstrasz, Nathanael Schärli, Roel Wuyts, Andrew P. Black: (Traits: A mechanism for fine-grained reuse. ) ''ACM Trans. Program. Lang. Syst.'' 28(2): 331-388 (2006)〕 similar to mixins. Traits provide a simple way to create classes that reuse behavior from software components.
Traits are somewhat between an interface and a mixin: an interface may define one or more behaviors via method signatures, while a trait defines behaviors via full method definitions, on the other side mixins include full method definitions and may also carry ''state'' through attributes while traits usually don't.
An interface is ''used'' by a class by "implementing" its methods.
A mixin is used by a class by mixing-into itself all the features of the mixin: i.e. the attributes and the methods.
A trait is used by a class by merging the collection of extra methods provided with some mechanism to resolve name conflicts.
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 repeated 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:
* 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 additional methods possibly overriding some of the methods of an existing trait
* alias: an operation that creates a new trait by adding a new name for an existing method
* and exclusion: an operation that forms a new trait by removing a method from an existing trait. (Combined with the alias operation yields a ''shallow rename'' operation).
A trait differs from an interface in that it provides implementations of its methods, not just type signatures.
==Properties==
Traits have the following properties:
* Provides a set of methods that implement behaviour.
* Requires a set of methods that parameterize the provided behaviour.
* Traits can be composed:
*
* Trait composition is symmetric; 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.〔http://web.cecs.pdx.edu/~black/publications/TR_CSE_02-012.pdf〕

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Trait (computer programming)」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.