implement replace() method for Component