txt: ## role.md
  role
  
  Combined from primary sources listed below.
  
  # [In Object orientation](#___top "go to top of document")[§](#(Object_orientation)_role_role "direct link")
  
  See primary documentation
  [in context](/language/objects#Roles)
  for **Roles**.
  
  Roles are a collection of attributes and methods; however, unlike classes, roles are meant for describing only parts of an object's behavior; this is why, in general, roles are intended to be *mixed in* classes and objects. In general, classes are meant for managing objects and roles are meant for managing behavior and code reuse within objects.
  
  Roles use the keyword `role` preceding the name of the role that is declared. Roles are mixed in using the `does` keyword preceding the name of the role that is mixed in.
  
  Roles can also be mixed into a class using `is`. However, the semantics of `is` with a role are quite different from those offered by `does`. With `is`, a class is punned from the role, and then inherited from. Thus, there is no flattening composition, and none of the safeties which `does` provides.
  
  ```raku
  constant ⲧ = " " xx 4; #Just a ⲧab
  role Notable {
      has Str $.notes is rw;
  
      multi method notes() { "$!notes\n" };
      multi method notes( Str $note ) { $!notes ~= "$note\n" ~ ⲧ };
  
  }
  
  class Journey does Notable {
      has $.origin;
      has $.destination;
      has @.travelers;
  
      method Str { "⤷ $!origin\n" ~ ⲧ ~ self.notes() ~ "$!destination ⤶\n" };
  }
  
  my $trip = Journey.new( :origin<Here>, :destination<There>,
                          travelers => <þor Freya> );
  
  $trip.notes("First steps");
  notes $trip: "Almost there";
  print $trip;
  # OUTPUT:
  #⤷ Here
  #       First steps
  #       Almost there
  #
  #There ⤶
  
  ```
  
  Roles are immutable as soon as the compiler parses the closing curly brace of the role declaration.
  
  # [In Glossary](#___top "go to top of document")[§](#(Glossary)_role_role "direct link")
  
  See primary documentation
  [in context](/language/glossary#Roles)
  for **Roles**.
  
  Roles, mix-ins or traits define interfaces and/or implementation of those interfaces as well as instance variables using them, and are mixed-in when declaring classes that follow that interface. [Abstract classes](#Abstract_class) are particular examples of Roles where the actual implementation is deferred to the class that uses that Role.
  
  Roles are part of Raku's [object system](/language/objects), and are declared using the [role](/language/objects#index-entry-role_declaration-role) keyword and used in class declaration via [does](/routine/does).
  