How do I share Screen code?

I want to share the following code with multiple screens. How do I do that ?
Do I put the code in its own class ? and if so, what would that class look like ?

    public Component generateUrgencyHtml(Visit entity){
        String html;
        if (entity.getUrgencyLevel() == null)
            return null;
        html = entity.getUrgencyLevel() == null ? "": entity.getUrgencyLevel().getHtml();
        Label<String> label = uiComponents.create(Label.TYPE_STRING);
        label.setValue(html);
        label.setHtmlEnabled(true);
        return label;
    }

Hi.
You can use Spring Bean for this purpose, for example.

Regards,
Natalia

Thank you Natalia !