# Реализации на Kotlin

## Общая реализация на языке Kotlin

{% tabs %}
{% tab title="ICommand" %}
{% code fullWidth="true" %}

```kotlin
fun interface ICommand {
    operator fun invoke()
}
```

{% endcode %}
{% endtab %}

{% tab title="CopyCommand" %}
{% code fullWidth="true" %}

```kotlin
class CopyCommand : ICommand {
    override operator fun invoke() {
        println("Copying document.")
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="PrintCommand" %}
{% code fullWidth="true" %}

```kotlin
class PrintCommand : ICommand {
    override operator fun invoke() {
        println("Printing document.")
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="ScanCommand" %}
{% code fullWidth="true" %}

```kotlin
class ScanCommand : ICommand {
    override operator fun invoke() {
        println("Scanning document.")
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Invoker" %}
{% code fullWidth="true" %}

```kotlin
class Invoker(var command: ICommand) {
    fun execute() {
        println("Executing...")
        command()
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% code lineNumbers="true" fullWidth="true" %}

```kotlin
fun main() {
    val copyCommand = CopyCommand()
    val scanCommand = ScanCommand()
    val printCommand = PrintCommand()

    val printer = Invoker(copyCommand)
    printer.execute()

    printer.command = scanCommand
    printer.execute()

    printer.command = printCommand
    printer.execute()
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://y2kot.gitbook.io/untitled/patterns/behavioral-patterns/command/realizacii-na-kotlin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
