Help for implementing interface
-
Hi all i have one interface and i have to implement it in different classes so i am confused to call method of interface. below is my code Public Interface MyInterface Function increment(ByVal Inc As MyInterface) As MyInterface End Interface Public Class MyClass1 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Public Class MyClass2 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Public Class MyClass3 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Calling this method Select Case objecttype Case ObjMyClass1 ObjMyClass1.increment() Case ObjMyClass2 ObjMyClass2.increment() Case ObjMyClass3 ObjMyClass3.increment() Now when i am calling this method increment i dont have object of MyInterface so what exactly i should pass in this method????So that i can increment particular value as per their class type (i.e. MyClass1,MyClass2,MyClass3) Please help me in this Thanks in advanced If u are not clear in my que you can ask me DJ Rock
-
Hi all i have one interface and i have to implement it in different classes so i am confused to call method of interface. below is my code Public Interface MyInterface Function increment(ByVal Inc As MyInterface) As MyInterface End Interface Public Class MyClass1 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Public Class MyClass2 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Public Class MyClass3 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Calling this method Select Case objecttype Case ObjMyClass1 ObjMyClass1.increment() Case ObjMyClass2 ObjMyClass2.increment() Case ObjMyClass3 ObjMyClass3.increment() Now when i am calling this method increment i dont have object of MyInterface so what exactly i should pass in this method????So that i can increment particular value as per their class type (i.e. MyClass1,MyClass2,MyClass3) Please help me in this Thanks in advanced If u are not clear in my que you can ask me DJ Rock
hi there, Review the following code i hope this will help you.
Private Sub IncrementObject(Object obj) Dim incrementor As MyInterface incrementor = CType(obj, MyInterface) incrementor.increment() End Sub Private Sub Main() Dim class1 As New MyClass1 Dim class2 As New MyClass2 Dim class3 As New MyClass3 IncrementObject(class1) IncrementObject(class2) IncrementObject(class3) End Sub
:)
Confidence comes not from always being right, but from not fearing to be wrong. Mihir..
-
Hi all i have one interface and i have to implement it in different classes so i am confused to call method of interface. below is my code Public Interface MyInterface Function increment(ByVal Inc As MyInterface) As MyInterface End Interface Public Class MyClass1 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Public Class MyClass2 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Public Class MyClass3 Implements MyInterface Public Function increment(ByVal Inc As MyInterface) As MyInterface Implements MyInterface.increment 'implementation End Function End Class Calling this method Select Case objecttype Case ObjMyClass1 ObjMyClass1.increment() Case ObjMyClass2 ObjMyClass2.increment() Case ObjMyClass3 ObjMyClass3.increment() Now when i am calling this method increment i dont have object of MyInterface so what exactly i should pass in this method????So that i can increment particular value as per their class type (i.e. MyClass1,MyClass2,MyClass3) Please help me in this Thanks in advanced If u are not clear in my que you can ask me DJ Rock
Acc. to your interface declaration. I'm not clear why you need a parameter of type "myInterface" in function. However, if you still want to use create an object of myInterface and pass them as parameter in function
Regards, Akhilesh Yadav
-
hi there, Review the following code i hope this will help you.
Private Sub IncrementObject(Object obj) Dim incrementor As MyInterface incrementor = CType(obj, MyInterface) incrementor.increment() End Sub Private Sub Main() Dim class1 As New MyClass1 Dim class2 As New MyClass2 Dim class3 As New MyClass3 IncrementObject(class1) IncrementObject(class2) IncrementObject(class3) End Sub
:)
Confidence comes not from always being right, but from not fearing to be wrong. Mihir..
Thank you so much for your help but thing is where should i declare IncrementObject function and i want to pass value which i have to increment. Let me clear my self suppose i have different type for numbers(i.e. sequential, numeric) ok? so in sequential increment will be done 1,2,3 like that. in numeric increment will be done like 1.0,1.1,1.1.1, or 2.0,2.1,2.1.1 OK??? SO for that i have one interface INumber public interface Inumber function increment(-----)as ----- end interface public class sequential implements Inumber public function increment(----) as ---- 'so here increment by one will happen end function end class public class numeric implements Inumber public function increment(----) as ---- 'so here increment by 0.1 or 0.0.1 will happen end function end class hope you get me now when i am calling this function i am checking for its type. If it is sequential then i will call sequential's increment and if it is numeric then i will call numeric's increment function Please tell me what should i pass in that function and return from that function Thank you so much
-
Thank you so much for your help but thing is where should i declare IncrementObject function and i want to pass value which i have to increment. Let me clear my self suppose i have different type for numbers(i.e. sequential, numeric) ok? so in sequential increment will be done 1,2,3 like that. in numeric increment will be done like 1.0,1.1,1.1.1, or 2.0,2.1,2.1.1 OK??? SO for that i have one interface INumber public interface Inumber function increment(-----)as ----- end interface public class sequential implements Inumber public function increment(----) as ---- 'so here increment by one will happen end function end class public class numeric implements Inumber public function increment(----) as ---- 'so here increment by 0.1 or 0.0.1 will happen end function end class hope you get me now when i am calling this function i am checking for its type. If it is sequential then i will call sequential's increment and if it is numeric then i will call numeric's increment function Please tell me what should i pass in that function and return from that function Thank you so much
hi there, more appropriate solution is as follows
Private Sub IncrementObject(INumber incrementor) incrementor.Increment() End Sub Public Shared Sub Main() Dim s As New Sequential() Dim n As New Numeric() '' '' This will execute Increment logic of Sequential Class IncrementObject(s); '' '' This will execute Increment logic of Numeric Class IncrementObject(n); End Sub
Above method accepts object of type INumber, so any number of classes in which you implement INumber interface can be passed as argument in this method and this method will execute appropriate logic of increment, Instance of Sequential Type will execute its own increment method.
Confidence comes not from always being right, but from not fearing to be wrong. Mihir..
-
hi there, more appropriate solution is as follows
Private Sub IncrementObject(INumber incrementor) incrementor.Increment() End Sub Public Shared Sub Main() Dim s As New Sequential() Dim n As New Numeric() '' '' This will execute Increment logic of Sequential Class IncrementObject(s); '' '' This will execute Increment logic of Numeric Class IncrementObject(n); End Sub
Above method accepts object of type INumber, so any number of classes in which you implement INumber interface can be passed as argument in this method and this method will execute appropriate logic of increment, Instance of Sequential Type will execute its own increment method.
Confidence comes not from always being right, but from not fearing to be wrong. Mihir..