Polymorphism

  • Thread starter Thread starter whoopding
  • Start date Start date
W

whoopding

Could anyone please give me an example of a realistic use of polymorphism.
 
We use the following scenario for running long processes and
displaying a UI.

Interface for all long processes (the code that does the process):

Public Interface ILongProcess
Event Progress(ByVal sender As Object, ByVal e As
ProgressEventArgs)
Event Completed(ByVal sender As Object, ByVal e As EventArgs)

Sub Start(ByVal state As Object)
Sub Cancel()
ReadOnly Property IsCancelled() As Boolean
ReadOnly Property IsCompleted() As Boolean
ReadOnly Property Title() As String
ReadOnly Property AnimationSource() As AnimationType
ReadOnly Property ResourceName() As String
ReadOnly Property ShowProgressBar() As Boolean
End Interface

And then we have the form which displays the progress bar, animation,
and has a cancel button.

Class LongProcessForm
Inherits Form

Public Sub New(process As ILongProcess)
...
End Sub
End Class

And then we have a bunch of processes..

Class CopyProcess Implements ILongProcess
Class DeleteProcess Implements ILongProcess
etc..


so the long processes can all take advantage of the single UI form to
display their UI and provide animation, progress bar, and cancel
functionality.

HTH,

Sam



Could anyone please give me an example of a realistic use of polymorphism.

B-Line is now hiring one VB.NET developer for
WinForms + WebServices position with ASPX in future.
Seaking mid to senior level developer. For
information or to apply e-mail sam_blinex_com.
 
Thanks
Samuel R. Neff said:
We use the following scenario for running long processes and
displaying a UI.

Interface for all long processes (the code that does the process):

Public Interface ILongProcess
Event Progress(ByVal sender As Object, ByVal e As
ProgressEventArgs)
Event Completed(ByVal sender As Object, ByVal e As EventArgs)

Sub Start(ByVal state As Object)
Sub Cancel()
ReadOnly Property IsCancelled() As Boolean
ReadOnly Property IsCompleted() As Boolean
ReadOnly Property Title() As String
ReadOnly Property AnimationSource() As AnimationType
ReadOnly Property ResourceName() As String
ReadOnly Property ShowProgressBar() As Boolean
End Interface

And then we have the form which displays the progress bar, animation,
and has a cancel button.

Class LongProcessForm
Inherits Form

Public Sub New(process As ILongProcess)
...
End Sub
End Class

And then we have a bunch of processes..

Class CopyProcess Implements ILongProcess
Class DeleteProcess Implements ILongProcess
etc..


so the long processes can all take advantage of the single UI form to
display their UI and provide animation, progress bar, and cancel
functionality.

HTH,

Sam





B-Line is now hiring one VB.NET developer for
WinForms + WebServices position with ASPX in future.
Seaking mid to senior level developer. For
information or to apply e-mail sam_blinex_com.
 
how about

IDBConnection? when you want a routine that works with a database
connection, but want it to work with any connection, be it

SQLConnection, OleDbConnection, or whatever supports IDBConnection

there are also interfaces for the command object, datareader, dataadapter,
etc.

Shane
 
I just finished a class heirarchy with the following methods (VB 6)

AddCharge(byref ch as Charge)
AddAdjustment(byref adj as Adjustment)

I would have loved to be able to write:

Add(byref ch as Charge)
Add(byref adj as Charge)

and used the VB.Net Option Strict to have the compiler enforce the
interface. It would actually make the code in this case significantly
cleaner; ie, I ended up with this mess in multiple places:

select case vartype(obj)
case "Charge": AddCharge(obj)
case "Adjustment": AddAdjustment(obj)
end select

Instead of

Add(obj)

and let the compiler figure it out.

Mike Ober.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top