Solved

Using interface as a variable type (sub parameter)

Posted on 2004-04-17
7
203 Views
Last Modified: 2010-04-24
I have an interface:

Public Interface jobDescription
    Sub ShowDuties()
End Interface

in Person.vb (class module) which is joined to my project by reference (.DLL)
The code for ShowDuties() is defined in several subclasses which inherit from the Person abstract class
So far there is no problem.

I am required to create a form level subroutine (in Form1.vb) as follows:
    Public Sub displayDuties(ByVal job As jobDescription)
         (bla bla bla)
    End Sub

the problem is that "jobDescription" in this sub is not recognised as a valid identifier. My notes state that the purpose of this function is to be able to call it using a variety of subclasses of Person, using the "jobDescription" interface to identify it, and then call the showDuties() subroutine (each one different) regardless of what type of Person was sent to displayDuties.
There is so much code I can't post it all here, but I hope you can get the general idea of what I need to do, and what the problem is, and how to fix it. I've spent hours searching through MSDN and can't find a single example of using an interface identifier as a variable type.
(I am using VB.NET, not 2003 or 2004)
thanks
Adam
0
Comment
Question by:adamjsawyerj
  • 3
  • 3
7 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 65 total points
ID: 10861492
An Interface is use in object-oriented program as a set of properties, methods, and events that are necessary to implement a certain type of functionality.  The IDisposable interface is an example, where you, if you implement all that is necessary will give you the functionality of being able to use the .Dispose method of an object to force garbage collection so that you can determine when it will occur.  You are mixing interfaces with just a base class and inheritance.

Bob
0
 

Author Comment

by:adamjsawyerj
ID: 10869463
I am not disputing that the information given was accurate, only that it was not relevant. I accepted the answer because there were no other answers to accept, and I didn't want the question drawn out after I had worked it out for myself. I mean no offense by the grade I gave, but stand by the grade because the answer given did not help me.
adam
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10870430
How did you work it out for yourself?

Bob
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:adamjsawyerj
ID: 10870570
   Public Sub displayDuties(ByVal job As persons.jobDescription)
      bla bla bla
    End Sub

I simply needed to prefix jobDescription with the base class containing the jobDescription interface. I didn't need to know about the theory of base classes or interfaces, just how to get the compiler to recognise my interface variable. I meant no offence by giving a low grade, but could hardly consider it a good answer when it was a large tangent from the given problem. I trust you will understand this. I did post a message explaining this at the time of grading, but it seems to have disappeared or not got there at all.
regards
adam
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10870593
No offense taken.  All grades of C need an explanation.  It is possible to make assumptions or incorrect guesses as to what people are talking about, which I certainly made in my case.  Also, programming is a continuously dynamic learning process, so I try to never take any hardline stances with anything.

Bob
0
 

Author Comment

by:adamjsawyerj
ID: 10870603
Looking back over my question, I can perhaps understand that I didn't give enough relevant information. Perhaps this led to the expert not fully understanding my problem. I apologise if this is the case, and if the grade should be changed then go ahead.
sorry
adam
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LINQ - C# to VB convertion 12 56
scanning dentists xray (the small ones) 3 53
SQL syntax in VB.net 5 39
How to retrieve a mysql date column that has 0000-00-00 in vb.net 8 32
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question