> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/d/delegates.md).

# Delegates

```ruby
class NonDelegate { }

class Delegate {
    method thing {
        return "delegate implementation"
    }
}

class Delegator (delegate = null) {
    method operation {

        if (delegate.respond_to(:thing)) {
            return delegate.thing
        }

        return "default implementation"
    }
}

var d = Delegator()
say "empty: #{d.operation}"
d.delegate = NonDelegate()
say "NonDelegate: #{d.operation}"
d.delegate = Delegate()
say "Delegate: #{d.operation}"
```

## Output:

```
empty: default implementation
NonDelegate: default implementation
Delegate: delegate implementation
```
