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. Interface Design : Hiding Members

Interface Design : Hiding Members

Scheduled Pinned Locked Moved ASP.NET
designhelptutorialquestion
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
    DIMPLE_R
    wrote on last edited by
    #1

    I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple

    M D 3 Replies Last reply
    0
    • D DIMPLE_R

      I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple

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

      public interface IInterfaceA
      {
      void MethodA();
      void MethodB();
      }

      public class X : IInterfaceA
      {
      void IInterfaceA.MethodA() { }
      void IInterfaceA.MethodB() { }

      public void MethodC() { }
      public void MethodD(){}
      

      }

      Explicit Interface Implementation[^]

      1 Reply Last reply
      0
      • D DIMPLE_R

        I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple

        D Offline
        D Offline
        DIMPLE_R
        wrote on last edited by
        #3

        Hi, Thanx for the info...But I was trying to implement this with VB.Net..Saw a few posts on the topic..Was wondering why this feature has been highlighted as an advantage point in C#...Can i not do the same in VB.Net? Dimple

        P M 2 Replies Last reply
        0
        • D DIMPLE_R

          Hi, Thanx for the info...But I was trying to implement this with VB.Net..Saw a few posts on the topic..Was wondering why this feature has been highlighted as an advantage point in C#...Can i not do the same in VB.Net? Dimple

          P Offline
          P Offline
          Paddy Boyd
          wrote on last edited by
          #4

          Could you just do this: interface A { Method A Method B } interface B { Method C Method D } Class X: Interface A, Interface B { ... etc. } And then have user only instantiate one of type a or type b.

          1 Reply Last reply
          0
          • D DIMPLE_R

            Hi, Thanx for the info...But I was trying to implement this with VB.Net..Saw a few posts on the topic..Was wondering why this feature has been highlighted as an advantage point in C#...Can i not do the same in VB.Net? Dimple

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

            Hmm, I'm not a true VBer :), but you might think of hidding the interface's methods in the implementation class with the low access level like private or protected:

            Public Interface IInterfaceA
            Sub MethodA()
            Sub MethodB()
            End Interface

            Public Class X
            Implements IInterfaceA

            Private Sub MethodA() Implements IInterfaceA.MethodA
            End Sub
            Protected Sub MethodB() Implements IInterfaceA.MethodB
            End Sub
                   
            Public Sub MethodC()
            End Sub
            Public Sub MethodD()
            End Sub
            

            End Class

            Btw, for this kind of question, you might want to ask in the VB.NET forum.

            1 Reply Last reply
            0
            • D DIMPLE_R

              I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple

              D Offline
              D Offline
              DIMPLE_R
              wrote on last edited by
              #6

              thanks minhpc_bk

              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