Trait

Term

Trait

Aliases

-

Identity

  • Term ID: src/main/doxsite/glossary/object-foundation/trait.dox

  • English label: Trait

  • Japanese label: トレイト

  • Category: Object Foundation

  • Status: normative

  • Definition authority: SimpleModeling BoK

DEFINITION

A Trait is a SimpleModeling-specific Classifier that defines reusable Features, Responsibilities, Capabilities, and Constraints as a partial model composable into multiple Classes or other Traits. A Trait is an Object Model element for cross-cutting structure and behavior rather than a Domain Model’s conceptual trunk or an independent unit of instantiation.

UML

UML 2.5.1 has no distinct Trait metaclass. In a UML Profile mapping, a SimpleModeling Trait is represented by default as an abstract Class carrying a «trait» stereotype, preserving Attributes, Associations, Operations, Constraints, and default Behavior. A contract-only Trait may be reduced to an Interface, but that mapping can lose partial structure or default Behavior. Generalization represents Trait application only when substitutability holds; a profile-specific relationship is required to represent mixin composition precisely.

Common Usage

Trait meanings differ across languages. A SimpleModeling Trait is not another name for Scala syntax; it is a Model Element defined in CML. Scala trait is a natural realization target, but not every language-level trait represents a SimpleModeling Trait.

Object-Functional Paradigm

On the object side, a Trait separates cross-cutting Capabilities and partial structures from an Object’s conceptual trunk and composes them into Classes. On the functional side, the same Capability may connect to functions, result types, effects, and type classes. A SimpleModeling Trait and a Type Class remain distinct concepts.

CML

CML (Cozy Modeling Language) defines Trait as an Object kind. A Trait may describe reusable Attributes, Associations, Operations, Responsibilities, Constraints, and related elements and be composed by Classes or other Traits. A Class’s conceptual Identity or Lifecycle is not moved into a Trait merely for reuse.

Scala

Scala trait is a primary realization target for a SimpleModeling Trait. Abstract and concrete members and mixin composition can realize partial structure and default Behavior. A generation policy may split one CML Trait across multiple Scala traits or supporting Types, so the mapping is not necessarily one-to-one.

simplemodeling-lib

The simplemodeling-lib Type Modeling Rule uses abstract class for conceptual trunks, inheritance invariants, state, and constructor semantics and uses trait for supplementary composable Capabilities. This aligns with the intent of SimpleModeling Trait, but implementation traits such as Holders, utilities, and type classes are not all promoted to Model Traits.

Public Usage

Japanese articles and videos introduce the term as トレイト(Trait). Its distinction from Class is explained as "a Class is a conceptual trunk; a Trait is a reusable partial model composed into multiple Classes." Its distinction from Interface is explained as "an Interface is an external contract; a Trait is a partial model that may also carry structure and default Behavior."

Boundary

  • Trait is not synonymous with Class and is not the primary classification unit for independent Instances.

  • Trait is not synonymous with Interface. A Trait may carry structure, Constraints, and default Behavior.

  • SimpleModeling Trait is not synonymous with Scala trait.

  • Trait is not synonymous with Type Class.

  • Type

  • Classifier

  • Class

  • Interface

  • Feature

  • Responsibility

  • Capability

  • Object-Functional Paradigm

References