|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Regarding componet architecture in VB.NETHi,
I need a help regarding writing an application which has two components which are inherited by a base component and depending on which object is associated during the calling the methods in the derived components should get called. How does VB.NET supports this approach. Thanks in Advance. If I understand you correctly, you have a base class and two components
derived from this base class, right? If so, unless you explicitly call the base class methods or properties using MyBase, it will be the overiding methods that are called, when you call a method on an instance of you component. However, if you choose not to override a method or property in the derived class, the base class method or property is called. Does that make sense? -- Show quoteCarsten Thomsen Communities - http://community.integratedsolutions.dk <sonali_reddy***@yahoo.com> wrote in message news:1129298682.962361.86070@g43g2000cwa.googlegroups.com... > Hi, > > I need a help regarding writing an application which has two components > which are inherited by a base component and depending on > which object is associated during the calling the methods in the > derived components should get called. > > > How does VB.NET supports this approach. > > > Thanks in Advance. > Well, your post is a bit vague, but I think I get the general idea.
You have a base component class. (We'll call it BaseComponent.) You have two other components that derive from the base component class. (DeriveComponentA and DerivedComponentB.) You want to have a method that takes a type of the BaseComponent and invokes the appropriate method on the derived component. Good news! Visual Basic .NET completely supports this functionality. Public MustInherit Class BaseComponent Public MustOverride Sub DoSomething() End Sub End Class Public Class DerivedComponentA Inherits BaseComponent Public Overrides Sub DoSomething() Debug.WriteLine("This is DerivedComponentA!") End Sub End Class Public Class DerivedComponentB Inherits BaseComponent Public Overrides Sub DoSomething() Debug.WriteLine("This is DerivedComponentB!") End Sub End Class Public Sub Main() DoSomeOtherStuff(New DerivedComponentA()) DoSomeOtherStuff(New DerivedComponentB()) End Sub Private Sub DoSomeOtherStuff(ByVal c As DerivedComponent) c.DoSomething() End Sub That should do what you want, unless I completely misconstrued your question. |
|||||||||||||||||||||||