tuwiendsg / MELA

Monitoring and analyzing elasticity of cloud services
http://tuwiendsg.github.io/MELA/
2 stars 4 forks source link

Provide fluent interfaces for all domain objects #14

Closed olmoser closed 10 years ago

olmoser commented 10 years ago

Besides the traditional Java Beans getters and setters, it makes code more concise and readable if fluent interface methods methods are provided to mutate members. As an example consider the MonitoredElement class with the following fluent interface methods:

public MonitoredElement withId(String id) {
    this.id = id;
    return this;
}

public MonitoredElement withName(String name) {
    this.name = name;
    return this;
}

public MonitoredElement withLevel(MonitoredElementLevel level) {
    this.level = level;
    return this;
}

such fluent interface methods should be provided for (domain) objects that require a lot of mutators to be invoked (and with fluent interfaces we can nicely chain those invocations and even bring structure to the mutator invocations by using appropriate indention). E.g.:

MonitoredElement topology = new MonitoredElement().withId("ServiceTopology").withLevel(MonitoredElement.MonitoredElementLevel.SERVICE_TOPOLOGY);