Starting with a simple super class
public class MySuperSearch {
private Data myData;
}
By default we are showing something on screen, based on myData, we are also using myData in other methods. One team had a specific use case where it made sense to reuse this classes functionality except showing that item on screen.
He did this
public class MySuperSearch {
protected Data myData; //changed access rights
}
public class MySubSearch {
public MySubSearch() {
....
myData = null; //has side effects
}
}
We all had a discussion about this and agreed we should be allowing extension to change behaviour, but not modification like above.
So the solution is something like the following
public class MySuperSearch {
private Data myData;
protected boolean isMyDataDisplayed() {
return true;
}
}
public class MySubSearch {
@Override
protected boolean isMyDataDisplayed() {
return false;
}
}
My question is what is the name of this pattern, so we can more concisely explain in the future?
Aucun commentaire:
Enregistrer un commentaire