Just Me,
I have two forms. Each contains a property, say Prop.
Is there a good way to do this?
Polymorphism, one of the tenants of OO, is a good way to do this. You can
use either Class Inheritance or Interface Implementation to achieve this
Polymorphism.
' Class Inheritance
Public Class BaseForm
Inherits System.Windows.Forms.Form
Public Property Prop As Integer
...
End Class
Public Class Form1
Inherits BaseForm
...
End Class
Public Class Form2
Inherits BaseForm
...
End Class
Public FormBeingUsed as BaseForm
FormBeingUsed= Form1
FormBeingUsed.Prop=123
FormBeingUsed=Form2
FormBeingUsed.Prop=123
' Interface Implementation
Public Interface IProp
Public Property Prop As Integer
...
End Interface
Public Class Form1
Inherits System.Windows.Forms.Form
Implements IProp
Public Property Prop As Integer Implements IProp.Prop
...
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
Implements IProp
Public Property Prop As Integer Implements IProp.Prop
...
End Class
Public FormBeingUsed as IProp
FormBeingUsed= Form1
FormBeingUsed.Prop=123
FormBeingUsed=Form2
FormBeingUsed.Prop=123
You could define Prop to be Overridable in BaseForm or define an
OnPropChanged method that the BaseForm.Prop.Set method calls when the value
changes if you need derived forms to know about the value of Prop
changing...
I would favor Class Inheritance over Interface Implementation as normally
Class Inheritance will produce less code.
Hope this helps
Jay