I have a Private Sub Modify() inside a form class A to handle the behaviour of a button or label (both belong to the same A class).
Let’s say it does this:
Private Sub Modify()
btnFoo.Enabled = True
lblBar.Text = "labelbar"
End Sub
If i move my Private Sub Modify() from the form class A to a module B and name it Public Sub Modify all I have to do to change the behaviour of the same button or label is something like this:
Public Sub Modify()
A.btnFoo.Enabled = True
A.lblBar.Text = "labelbar"
End Sub
But would this be aproppiate, considering the modules are some kind of static elements?
I would like to know the propper way, so i could keep up with good practices.
Thanks in advance.
It’s almost never a good idea for a module, class, or anything else to access another object’s properties multiple levels deep like that. If nothing else, it breaks The Law of Demeter. In more general terms, it’s not a good idea to have anything outside of the form manipulate any of a form’s controls directly. I think it’s regrettable that controls are public, by default, in the first place. It would be better to leave the
Modifymethod on the form and just make itPublicif you need to call it from outside the form.