check the call to a method in VB.NET

admin

Administrator
Staff member
Im using VB.NET at the moment, and i have 2 classes Employee and RestrictedEmployee and the Employee class has a method called, changePin().

As you may have guessed RestrictedEmployee class inherits from Employee.

The problem I am having is that a RestrictedEmployee is not allowed to change their pin, so i need to return false if the call to the method is done from the RestrictedEmployee class...

How do i do this?I am not completely sure of the syntax but there should be something like it in VB.net as it is in C#. use the keyword "override"....

i believe from my SDK it is "Overrides" but can not verify as I do not install vb.net usually. Trying to get away from the syntax.... Also you would get a 10% increase in speed in C#. as it is C++ like and all of the language features are implemented with code orginazation and such. Check out MS benchmarks for that.I would re-organize that code it should be restricted is the base class implementation and the unrestricted is implemented in the child class.

This is a better method as it works this way in nature. Parents hand children traits, children add new traits that parents don't have.if you tell me the complete method of usage here, I can help more with the design for stablity and scalablity.

How are you assigning the use of each of the classes? in Windows Forms or ASP.net? if your using ASP.net then I suggest you use Role Based authentation routing each to the correct method.

If Windows forms use the CAS to handle it no matter what implementation class libaray or windows forms. As you can explicitly create roles just as ASP.net but validate against the stack, it will walk the stack to validate that its not being called from untrusted code and executed in the wrong context so no one can use your library without the source code.Thanks man, i use the overriddes property of the method and it worked just fine...I know it works but your inheritance is backwards, I would suggest trying to revise it.backwards you say?

my employee class has the method:

Public Overridable Function changePin(ByVal oldPin As String, ByVal newPin As String) As Boolean

and the restrictedemployee class has the other one:

Public Overrides Function changePin(ByVal oldPin As String, ByVal newPin As String) As Boolean

is that correct?I mean your class should be like below


class Employee
{
//function(s) and variable(s)
}

class UnRestrictedEmployee:Employee
{
public UnRestrictedEmployee():base()
{

}

public bool changePin(String oldPin, String newPin String)
{

}


}

This is correct with inheritance. If you create an instance of Employee then it will never be able to execute change Pin, as it does not even implement the method. Its a way of extending a base class with out exposing functionality in the base class that is really not needed.

Notice that the changePin function is not in the class "Employee".i see what your saying...thanks man!
 
Back
Top