Shared Methods

A Shared method runs in the Class namespace and may be called via an Instance or via the Class. However, a Shared method that is called via an Instance does not have direct access to the Fields and Properties of that Instance.

Class Parrot has a Speak method that does not require any information about the current Instance, so may be declared as Shared.

:Class Parrot:Bird

     RSpeak times
      :Access Public Shared
      Rtimes⍴⊂'Squark!'
    

:EndClass ⍝ Parrot

      wild⎕NEW Parrot
      wild.Speak 2
 Squark!  Squark! 

Note that Parrot.Speak may be executed directly from the Class and does not in fact require an Instance.

      Parrot.Speak 3
 Squark!  Squark!  Squark!