vb.net - A case for interface? -


i have class should different things form.

because these "things" specific form, store reference form this:

friend class clsedit      private m_form frmmain 

and pass class this:

public sub new(byref uform frmmain)      m_form = uform  end sub 

now when class should these "things", this:

myeditclass.dothings() 

internally looks this:

public sub dothis()      m_form.sethookpaused(true)      m_form.stopcommontimers()  end sub  protected overrides sub finalize()     m_form.dosomethingthatonlythisformcando() end sub 

i able use clsedit on different form well. other form has functions "dothings" , "dosomethingthatonlythisformcando".

however, when change declaration of m_form this

private m_form form 

... can't anymore:

m_form.dothings() 

... because "dothings" not property / function of "form".

and when change this:

private m_form frmother 

... can't anymore:

public sub new(byref uform frmmain)      m_form = uform  end sub 

can tell me how this?

create interface:

public interface iformstuff   sub sethookpaused(value boolean)   sub stopcommontimers() end interface 

replace form variable interface variable in class:

public class clsedit   private m_form iformstuff    public sub new(f iformstuff)     m_form = f   end sub    public sub dothis()     m_form.sethookpaused(true)     m_form.stopcommontimers()   end sub end class 

implement interface in each form:

public class form1   implements iformstuff 

and each form needs implement interface stubs:

public sub sethookpaused(value boolean) implements iformstuff.sethookpaused   ' end sub  public sub stopcommontimers() implements iformstuff.stopcommontimers   ' end sub 

then need create class @ form level:

private myedit clsedit = nothing  protected overrides sub onload(e eventargs)   mybase.onload(e)   myedit = new clsedit(me) end sub 

that's gist of it.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -