Results 1 to 4 of 4

Thread: Variables and Interfaces

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Variables and Interfaces

    I am creating an object that implements quite a few interfaces. My problem is that there are a couple of variables that all the interfaces need access to. I know that I could put these variables in a module or shared class, but that is generally a sign of poor OOP design.

    Is there any way that I could implement this without using global variables?

    Here is a sample of the layout of the object. In the sample the Interfaces need to be able to get what the CurrentIndex is, but I don't want them to be able to change it at all. It should only be writeable from MainObject.

    VB Code:
    1. Public Interface MainObject
    2. ReadOnly Property CurrentIndex as Integer
    3. ReadOnly Property If1 as Interface1
    4. ReadOnly Property If2 as Interface2
    5. ReadOnly Property If3 as Interface3
    6.  
    7. Function SetCurrentIndex(index as Integer)
    8.  
    9. End Interface
    10.  
    11. Public Interface Interface1
    12.     ReadOnly Property P1 as Something
    13.     ReadOnly Property P2 as Something
    14.     ReadOnly Property P3 as Something
    15.     ReadOnly Property P4 as Something
    16.  
    17.     Function F1(ST as Something) As Something
    18.     Function F3(ST as Something) As Something
    19.     Function F2(ST as Something) As Something
    20. End Interface
    21.  
    22. Public Interface Interface2
    23.     ReadOnly Property P1 as Something
    24.     ReadOnly Property P2 as Something
    25.     ReadOnly Property P3 as Something
    26.     ReadOnly Property P4 as Something
    27.  
    28.     Function F1(ST as Something) As Something
    29.     Function F3(ST as Something) As Something
    30.     Function F2(ST as Something) As Something
    31. End Interface
    32.  
    33. Public Interface Interface3
    34.     ReadOnly Property P1 as Something
    35.     ReadOnly Property P2 as Something
    36.     ReadOnly Property P3 as Something
    37.     ReadOnly Property P4 as Something
    38.  
    39.     Function F1(ST as Something) As Something
    40.     Function F3(ST as Something) As Something
    41.     Function F2(ST as Something) As Something
    42. End Interface
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Variables and Interfaces

    I haven't done anything with interfaces, but I was always under the impression that an interface exposed a set of properties and functions from an underlying object. Is that not the case?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Variables and Interfaces

    What happens is that the main object is exposing the properties and functions from the other interfaces. But those interfaces need to know a couple of variables that is in the MainObject interface. I hope that makes sense (and I hope I am doing it right). This is the first time I have dealt with interfaces. I had a nice pretty class that worked, then my boss said he wanted it done with interfaces.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Variables and Interfaces

    Ok....Here is what I thimk I am going to do. I'd like to know if this is a good way or not to do it. And if not what is a better way. I am creating properties in the classes that get implemented, but I am not adding them as part of the interface. That way MainObject can access these properties, but they can not be accessed through the interface. Let me know what you think.

    Thanks
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width