Results 1 to 3 of 3

Thread: Interfaces and Unsupported Functionality

  1. #1

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Interfaces and Unsupported Functionality

    I have an interface I have written and I have a few user controls that implement the interface. The user controls each expose a third party control which have mostly identical functionality, but there are a few things that one control can do that others might not be able to do.

    So my question is

    1.)Do I use a single interface and throw NotSupported exceptions when the caller tries to use functionality that doesn't work in this particular implementation?
    Or
    2.)Do I break all of my functionality into separate interfaces and implement a whole bunch of interfaces in my usercontrol?
    Or
    3.)Do I do some Hybrid of 1 and 2, grouping certain functionality together?

    I am really trying to avoid #1, as it would require using exceptions to control program flow, which I hate doing. Also I want to disable functionality if it is not implemented, so the user can't even click the option in my UI if the control doesn't support it. I would fear I could run into this problem if I went down the road of #3 and we built a new control that implemented all but one function in an interface.

    So right now I am leaning towards #2, but I have a fear that it will make the code unmanageable.

    Does anyone have any suggestions?

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

    Re: Interfaces and Unsupported Functionality

    I would go with a single base interface that implements all that is common, then include other interfaces for the parts that are unique to one particular flavor. Therefore, every control would implement the base interface, and one or more of the other interfaces, depending on what other pieces are needed.
    My usual boring signature: Nothing

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Interfaces and Unsupported Functionality

    NotSupportedExceptions shouldn't really ever be used to control program flow. They are just there as a last line of defence. If you really do have a member that can reasonably not be supported then you should have a corresponding Boolean property that tells you whether or not the feature is supported or not. For instance, the NetworkStream.Seek method throws a NotSupportedException so the NetworkStream.CanSeek property returns False, while the FileStream.CanSeek property returns True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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