refactoring - refactor dilemma -
i want extract guard statement following method
private void createproxy() { //extract following guard statement. host selected = this.combobox1.selecteditem host; if (selected == null) { return; } this.searchproxy = serviceproxy.proxyfactory.createsearchproxy(getselectedip().tostring()); this.streamproxy = serviceproxy.proxyfactory.createplayerproxy(getselectedip().tostring()); } //extracted guard method public bool ishostselected() { host selected = this.combobox1.selecteditem host; if (selected == null) { return false; } return true; }
see? have add return value extracted method, kinda ugly?
any better solution avoid adding return value extracted method?
i don't see big deal. first, rewrite as:
static bool selecteditemishost(combobox box) { return box.selecteditem host; }
note rename, combobox
parameter, , body change.
now, makes code read more clearly:
void createproxy() { if(selecteditemishost(this.combobox1)) { this.searchproxy = serviceproxy.proxyfactory.createsearchproxy(getselectedip().tostring()); this.streamproxy = serviceproxy.proxyfactory.createplayerproxy(getselectedip().tostring()); } }
so reads "if selected item host
stuff."
now, goes way beyond question, looks big coupling of ui logic , domain logic. might want reconsider decoupling there.
Comments
Post a Comment