dimanche 18 décembre 2022

How should I build the methods of a Director class following the principles of SOLID

I'm studying creational design patterns. In the code below is the CommandDirector class. Following the builder design pattern, its only function is to set the processes it must execute to the command object's builder.

public class CommandDirector {

    public void createAddCommand(CommandBuilder builder) {
        builder
            .addProcess(new Process1())
            .addProcess(new Process2())
            .addProcess(new Process3());
    }
    
    public void createRemoveCommand(CommandBuilder builder) {
        builder
            .addProcess(new Process1())
            .addProcess(new Process3());
    }
    
    public void createUpdateCommand(CommandBuilder builder) {
        builder
            .addProcess(new Process1())
            .addProcess(new Process2());
    }
    
    public void createListCommand(CommandBuilder builder) {
        builder
            .addProcess(new Process2())
            .addProcess(new Process3());
    }
    
}

My question is whether this implementation follows the principles of SOLID. Because it also ends up having the function of creating the objects of the processes. Should I delegate the function of creating Process objects to a Process Factory?

Aucun commentaire:

Enregistrer un commentaire