Factories for Properties

Suppose you need buttons
with a specialized border...

    private void createButtons() {
        oneButton = new JButton("One");
        twoButton = new JButton("Two");
        treButton = new JButton("Tre");

        oneButton.setBorder(BorderFactory
                 .createLineBorder(Color.BLUE, 2));
        twoButton.setBorder(BorderFactory
                 .createLineBorder(Color.BLUE, 2));
        treButton.setBorder(BorderFactory
                 .createLineBorder(Color.BLUE, 2));
    }

...you could create a subclass...

    class NumButton extends JButton {
        public NumButton(String text) {
            super(text);
            setBorder(BorderFactory
                     .createLineBorder(Color.BLUE, 2));
        }
    }
    
    private void createButtons() {
        oneButton = new NumButton("One");
        twoButton = new NumButton("Two");
        treButton = new NumButton("Tre");
    }

...or you could write a factory method.

    private JButton createNumButton(String text) {
        JButton button = new JButton(text);
        button.setBorder(BorderFactory
                     .createLineBorder(Color.BLUE, 2));
        return button;
    }
    
    private void createButtons() {
        oneButton = createNumButton("One");
        twoButton = createNumButton("Two");
        treButton = createNumButton("Tre");
    }