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

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -