Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help for implementing interface

Help for implementing interface

Scheduled Pinned Locked Moved ASP.NET
helpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dj rock
    wrote on last edited by
    #1

    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

    M A 2 Replies Last reply
    0
    • D 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

      M Offline
      M Offline
      MihirV
      wrote on last edited by
      #2

      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..

      D 1 Reply Last reply
      0
      • D 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

        A Offline
        A Offline
        Akhilesh Yadav
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M MihirV

          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..

          D Offline
          D Offline
          dj rock
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • D dj rock

            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

            M Offline
            M Offline
            MihirV
            wrote on last edited by
            #5

            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..

            D 1 Reply Last reply
            0
            • M MihirV

              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..

              D Offline
              D Offline
              dj rock
              wrote on last edited by
              #6

              Thanks buddy i hope this will work ;)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups