
  /*

  How to attach an object of one class to another by reference.

  In this example a switch is attached to an electrical device.
  This attachment will also work for derived classes of both BasicSwitch and Electrical

  */

  class BasicSwitch
  =================

  sys state

  method style() as string
    return "plain"
  end method

  method on()
    state=1
  end method

  method off()
    state=0
  end method

  end class


  class ElectricalDevice
  ======================

  BasicSwitch * bswitch 'switch by reference

  method describe() as string
    string cr,s
    cr=chr(13)+chr(10)
    s="Description:" cr cr
    '
    if @bswitch then
      if bswitch.state then
        s+="Switch is on" cr
      else
        s+="switch is off" cr
      end if
    else
      s+="Switch has not been fitted"  
    end if
    return s
  end method 
  
  end class


  'SETUP
  '=====

  ElectricalDevice  device
  BasicSwitch bswitch

  'we have only dimensioned these objects. Constructors have not been used.

  'TESTING:
  '========

  print device.describe
  @device.bswitch = @bswitch 'attach bswitch
  print device.describe
  device.bswitch.on
  print device.describe


