lundi 8 juin 2015

Builder + Getter vs Setter and getter

I have a service client, which require 5 parameter need to passed for each function. Example:

domain
subject
date
serverId
clusterId

For each object, we need to call function like: createConnection list download

I am creating a wrapper for this. Which will take these 5 parameter as constructor argument and you need to just call createConnection, list and download without passing the values. Which pattern is better:

@Builder @Getter

ClientConfig {
    domain
    subject
    date
    serverId
    clusterId

}

or

@Builder @Setter

    ClientConfig {
        domain
        subject
        date
        serverId
        clusterId

    }

Examples in code:

ClientWrapper{
    ClientWrapper(ClientConfig config){
        this.config = config;
        this.client = new clientFactory.getClient();
    }

    download(){
        this.client.download(this.config.domain, ....);
    }
}

Vs

@Builder
ClientWrapper{
    domain
    subject
    date
    serverId
    clusterId

    download() {
     this.client.download(this.domain, ....);
    }
}

Aucun commentaire:

Enregistrer un commentaire