passing parameter as an interface type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wiredless

    passing parameter as an interface type

    What is the advantage of passing an interface type?

    according to UML (visio) when i reverse engineer existing code to a UML
    diagram I get the error

    "UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot be
    used as the type of a parameter."

    for this code:

    public void OnUpdate(CCC.Sy s.TestProc.ISam ple sample)
    {

    however the application does compile and run correctly.

    Yes its not my code.

    What is the advantage of passing an interface type?
    Since UML doesn't like it should I not do it?

    Thanks


  • Tom Porterfield

    #2
    Re: passing parameter as an interface type

    wiredless wrote:[color=blue]
    > What is the advantage of passing an interface type?
    >
    > according to UML (visio) when i reverse engineer existing code to a UML
    > diagram I get the error
    >
    > "UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot be
    > used as the type of a parameter."
    >
    > for this code:
    >
    > public void OnUpdate(CCC.Sy s.TestProc.ISam ple sample)
    > {
    >
    > however the application does compile and run correctly.
    >
    > Yes its not my code.
    >
    > What is the advantage of passing an interface type?
    > Since UML doesn't like it should I not do it?[/color]

    The advantage is that it makes your code less susceptible to requiring
    modification for future enhancements. By taking an interface type
    rather than a specific object, all you worry about is that whatever is
    passed support the functionality that the OnUpdate method needs. How
    the ISample object implements the interface does not matter to you.

    I'm not enough of a Visio and/or UML guru to say why the error is being
    generated.
    --
    Tom Porterfield

    Comment

    • Richard Blewett [DevelopMentor]

      #3
      passing parameter as an interface type

      Passing an interface as a method parameter is a totally valid thing to do. Consider this:

      interface IPolygon

      {

      void Draw();

      }

      class Visio

      {

      public void DrawDiagram(IPo lygon[] shapes)

      {

      foreach( IPolygon p in shapes )

      {

      p.Draw();

      }

      }

      }

      So you would think Visio should know better ;-)

      Regards

      Richard Blewett - DevelopMentor



      nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<#PeXt80nEHA.35 64@tk2msftngp13 .phx.gbl>

      What is the advantage of passing an interface type?

      according to UML (visio) when i reverse engineer existing code to a UML
      diagram I get the error

      "UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot be
      used as the type of a parameter."

      for this code:

      public void OnUpdate(CCC.Sy s.TestProc.ISam ple sample)
      {

      however the application does compile and run correctly.

      Yes its not my code.

      What is the advantage of passing an interface type?
      Since UML doesn't like it should I not do it?

      Thanks



      ---
      Incoming mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



      [microsoft.publi c.dotnet.langua ges.csharp]

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: passing parameter as an interface type

        wiredless,
        The others have discussed the advantages of using an Interface.

        The version of UML that Visio adheres to does not allow interfaces to be
        parameters, hence the error.

        However you can turn the check off using "UML - Options - UML Document -
        Relax semantic error checking".

        Hope this helps
        Jay


        "wiredless" <mobiledynamo@s printpcs.com> wrote in message
        news:%23PeXt80n EHA.3564@tk2msf tngp13.phx.gbl. ..[color=blue]
        > What is the advantage of passing an interface type?
        >
        > according to UML (visio) when i reverse engineer existing code to a UML
        > diagram I get the error
        >
        > "UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot
        > be
        > used as the type of a parameter."
        >
        > for this code:
        >
        > public void OnUpdate(CCC.Sy s.TestProc.ISam ple sample)
        > {
        >
        > however the application does compile and run correctly.
        >
        > Yes its not my code.
        >
        > What is the advantage of passing an interface type?
        > Since UML doesn't like it should I not do it?
        >
        > Thanks
        >
        >[/color]


        Comment

        • Paul

          #5
          Re: passing parameter as an interface type

          This thread was great, helped me out, cheers!

          Comment

          • DurayAkar

            #6
            Re: passing parameter as an interface type

            Can you bypass just a certain semantic error like this one ?

            I want to use the other semantic errors checked, but not this...

            Because the System classes has this structure themselves :)



            Comment

            • DurayAkar

              #7
              Re: passing parameter as an interface type

              Is it possible to exclude just this error instead of relaxing the whole
              deal?





              Comment

              Working...