Yesterday I was reviewing some Java code with a co-worker and we were discussing the Single Responsibility Principle. We refactored the code a bit and it complies very well to this principle.
Since I'm more of a front-end guy instead of backend I'm mostly writing JavaScript. Because of the SRP discussion I was looking at my code and found the following:
retrieveLabels : function() {
getResultFromService(this, url, function(labelObject) {
this.setLabels(labelObject)
});
}
This function, to me, doesn't comply to SRP, it retrieves the labels (asynchroniously) and it stores this object in a variable. So basicly I want to return labelObject
and pass the object to another function.
The problem here for me is the callback because it is asynchroniousl, how would one make this SRP compliant?