Solved

Using interface as a variable type (sub parameter)

Posted on 2004-04-17
7
202 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

862 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now