SDA SE Wiki

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

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

research:cultivate:objectconstructorparametervs.accessorconstructorparameter [2018/05/09 01:59] (current)
Line 1: Line 1:
  
 +==== object constructor parameter ====
 +
 +
 +<Code lang-java>​
 +
 +private String name;
 +
 +public Result(String name) {
 +  this.name = name;
 +}
 +
 +public String getName() {
 +  return name;
 +}
 +
 +</​Code>​
 +
 +
 +==== accessor constructor parameter ====
 +
 +
 +<Code lang-java>​
 +
 +private INameProvider nameProvider;​
 +
 +public Result(INameProvider nameProvider) {
 +  this.nameProvider = nameProvider;​
 +}
 +
 +public String getName() {
 +  return nameProvider.getName();​
 +}
 +
 +</​Code>​
 +
 +
 +==== 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 ====
 +
 +  - introduce common interface
 +  - 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