SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


object constructor parameter


private String name;

public Result(String name) {
  this.name = name;
}

public String getName() {
  return name;
}

accessor constructor parameter


private INameProvider nameProvider;

public Result(INameProvider nameProvider) {
  this.nameProvider = nameProvider;
}

public String getName() {
  return nameProvider.getName();
}

pros of accessor constructor parameter

  • represents semantics better if appropriate (name not part of one result but meta-property of many results)
  • changes of the meta-property directly visible in all objects
  • property can be initialized lazily

cons of accessor constructor parameter

  • harder to understand
  • harder to test?

refactor towards accessor contructor parameter

  1. introduce common interface
  2. replace direct access with access via interface parameter

similar refactorings

  • introduce parameter object (Fowler, p.295)
  • hide delegate (Fowler, p.157)
  • replace data value with object (Fowler, p.175)
research/cultivate/objectconstructorparametervs.accessorconstructorparameter.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019