<?php

interface Formatter
{
    public function format(string $text): string;
}


class PlainTextFormatter implements Formatter
{
    public function format(string $text): string
    {
        return $text;
    }
}


class HtmlFormatter implements Formatter
{
    public function format(string $text): string
    {
        return sprintf('<p>%s</p>', $text);
    }
}

abstract class Service
{
    protected Formatter $implementation;

    public function __construct(Formatter $printer)
    {
        $this->implementation = $printer;
    }

    public function setImplementation(Formatter $printer)
    {
        $this->implementation = $printer;
    }

    abstract public function get(): string;
}



class HelloWorldService extends Service
{
    public function get(): string
    {
        return $this->implementation->format('Hello World');
    }
}


class PingService extends Service
{
    public function get(): string
    {
        return $this->implementation->format('pong');
    }
}

// USAGE:
$service = new HelloWorldService(new PlainTextFormatter());
$service = new HelloWorldService(new HtmlFormatter());