Solved

Using interface as a variable type (sub parameter)

Posted on 2004-04-17
7
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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