C# language feature proposal

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

    #1

    C# language feature proposal

    I believe that interfaces are one of the more useful
    design constructs available in C#. However, there's one
    thing that I feel is missing in them. I propose that
    interfaces be expanded to allow the specification of
    constructors. Admittedly, this makes things a bit
    confusing in that seeing constructors in an interface
    seems to imply that the interface itself can be
    instantiated. But I don't believe that it would be
    significantly worse than the similar situation with
    methods. Often enough, a family of classes will be
    derived from an interface that are designed to have the
    same basic set of constructors.
  • Jon Skeet

    #2
    Re: C# language feature proposal

    Merlin <jgarza@hotmail .com> wrote:[color=blue]
    > I believe that interfaces are one of the more useful
    > design constructs available in C#. However, there's one
    > thing that I feel is missing in them. I propose that
    > interfaces be expanded to allow the specification of
    > constructors. Admittedly, this makes things a bit
    > confusing in that seeing constructors in an interface
    > seems to imply that the interface itself can be
    > instantiated. But I don't believe that it would be
    > significantly worse than the similar situation with
    > methods. Often enough, a family of classes will be
    > derived from an interface that are designed to have the
    > same basic set of constructors.[/color]

    And likewise static methods. It's been discussed before :)

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Harkos

      #3
      Re: C# language feature proposal

      Although I have seen explanations for not allowing this, I agree both would
      be a good addition to the language.

      []'s,
      Harkos

      "Jon Skeet" <skeet@pobox.co m> escreveu na mensagem
      news:MPG.19b9c4 709e394d3098a43 4@news.microsof t.com...[color=blue]
      > Merlin <jgarza@hotmail .com> wrote:[color=green]
      > > I believe that interfaces are one of the more useful
      > > design constructs available in C#. However, there's one
      > > thing that I feel is missing in them. I propose that
      > > interfaces be expanded to allow the specification of
      > > constructors. Admittedly, this makes things a bit
      > > confusing in that seeing constructors in an interface
      > > seems to imply that the interface itself can be
      > > instantiated. But I don't believe that it would be
      > > significantly worse than the similar situation with
      > > methods. Often enough, a family of classes will be
      > > derived from an interface that are designed to have the
      > > same basic set of constructors.[/color]
      >
      > And likewise static methods. It's been discussed before :)
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet/
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jasper Kent

        #4
        Re: C# language feature proposal

        What is the point of having constructors on interfaces? They can't have
        data, so what is there to construct? You may mean abstract constructors, but
        it would offer no benefit, since they could never be accessed though the
        interface reference, only through the implementation class.

        Statics is another issue.

        And constants.

        And type declarations.

        Regards,

        Jasper Kent.
        "Harkos" <harkos@uol.com .br> wrote in message
        news:OVGnzvHcDH A.2960@tk2msftn gp13.phx.gbl...[color=blue]
        > Although I have seen explanations for not allowing this, I agree both[/color]
        would[color=blue]
        > be a good addition to the language.
        >
        > []'s,
        > Harkos
        >
        > "Jon Skeet" <skeet@pobox.co m> escreveu na mensagem
        > news:MPG.19b9c4 709e394d3098a43 4@news.microsof t.com...[color=green]
        > > Merlin <jgarza@hotmail .com> wrote:[color=darkred]
        > > > I believe that interfaces are one of the more useful
        > > > design constructs available in C#. However, there's one
        > > > thing that I feel is missing in them. I propose that
        > > > interfaces be expanded to allow the specification of
        > > > constructors. Admittedly, this makes things a bit
        > > > confusing in that seeing constructors in an interface
        > > > seems to imply that the interface itself can be
        > > > instantiated. But I don't believe that it would be
        > > > significantly worse than the similar situation with
        > > > methods. Often enough, a family of classes will be
        > > > derived from an interface that are designed to have the
        > > > same basic set of constructors.[/color]
        > >
        > > And likewise static methods. It's been discussed before :)
        > >
        > > --
        > > Jon Skeet - <skeet@pobox.co m>
        > > http://www.pobox.com/~skeet/
        > > If replying to the group, please do not mail me too[/color]
        >
        >[/color]


        Comment

        • Daniel O'Connell

          #5
          Re: C# language feature proposal


          "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
          news:uC6jXNTcDH A.616@TK2MSFTNG P11.phx.gbl...[color=blue]
          > What is the point of having constructors on interfaces? They can't have
          > data, so what is there to construct? You may mean abstract constructors,[/color]
          but[color=blue]
          > it would offer no benefit, since they could never be accessed though the
          > interface reference, only through the implementation class.[/color]

          Abstract constructors is the idea, basically an attempt to define a method
          to require a given class to have a given constructor (needed for some
          patterns). I don't think this is something appropriate for an interface,
          myself.
          [color=blue]
          >
          > Statics is another issue.[/color]

          Explicit statics defined on the interface have no point, just stick them in
          a class. Defining that a class requires the existance of a static has its
          uses, but again isn't something an interface should do.[color=blue]
          >
          > And constants.
          >[/color]

          Why define a constant on an interface...tha ts what classes are for as well.
          If you want it associated with a specific interface, then a related class
          makes more sense than adding such things directly to the interface.
          [color=blue]
          > And type declarations.[/color]

          What do you mean?
          [color=blue]
          >
          > Regards,
          >
          > Jasper Kent.
          > "Harkos" <harkos@uol.com .br> wrote in message
          > news:OVGnzvHcDH A.2960@tk2msftn gp13.phx.gbl...[color=green]
          > > Although I have seen explanations for not allowing this, I agree both[/color]
          > would[color=green]
          > > be a good addition to the language.
          > >
          > > []'s,
          > > Harkos
          > >
          > > "Jon Skeet" <skeet@pobox.co m> escreveu na mensagem
          > > news:MPG.19b9c4 709e394d3098a43 4@news.microsof t.com...[color=darkred]
          > > > Merlin <jgarza@hotmail .com> wrote:
          > > > > I believe that interfaces are one of the more useful
          > > > > design constructs available in C#. However, there's one
          > > > > thing that I feel is missing in them. I propose that
          > > > > interfaces be expanded to allow the specification of
          > > > > constructors. Admittedly, this makes things a bit
          > > > > confusing in that seeing constructors in an interface
          > > > > seems to imply that the interface itself can be
          > > > > instantiated. But I don't believe that it would be
          > > > > significantly worse than the similar situation with
          > > > > methods. Often enough, a family of classes will be
          > > > > derived from an interface that are designed to have the
          > > > > same basic set of constructors.
          > > >
          > > > And likewise static methods. It's been discussed before :)
          > > >
          > > > --
          > > > Jon Skeet - <skeet@pobox.co m>
          > > > http://www.pobox.com/~skeet/
          > > > If replying to the group, please do not mail me too[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Jon Skeet

            #6
            Re: C# language feature proposal

            Jasper Kent <jasper_kent@ho tmail.com> wrote:[color=blue]
            > What is the point of having constructors on interfaces? They can't have
            > data, so what is there to construct? You may mean abstract constructors, but
            > it would offer no benefit, since they could never be accessed though the
            > interface reference, only through the implementation class.
            >
            > Statics is another issue.[/color]

            Not the way I'd considered it: these wouldn't be static methods with
            implementations , they would be "abstract static" methods - very similar
            to constructors. Basically it would ensure that implementors had the
            appropriate constructors/static methods so that they could be called by
            reflection. You'd still lose compile-time safety in the calling, but at
            least implementors could get a compile-time error if they forgot to
            implement the appropriate method/constructor. So yes, they *would*
            offer a benefit.
            [color=blue]
            > And constants.[/color]

            I don't see why they should go in interfaces particularly.
            [color=blue]
            > And type declarations.[/color]

            Nor those.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • Richard Cook

              #7
              Re: C# language feature proposal

              presumably statics and constructors in interfaces would be non-CLS
              compliant, so these would have to be ignored by languages that don't
              understand them. Explicit implementation would also be illegal?

              Still fail to see any real benefit; it doesn't enhance "interface based
              programming". It doesn't as far as I understand make a difference to any
              actual code. If it's mainly used for instantiation, for plugins etc, you
              won't get far if instantiation fails; I guess the application can't even
              assume the plugin class even implements the required i/f. Is there an
              enlightening example anywhere?



              "Jon Skeet" <skeet@pobox.co m> wrote in message
              news:MPG.19be7a 5f42213ced98a47 3@news.microsof t.com...[color=blue]
              > Jasper Kent <jasper_kent@ho tmail.com> wrote:[color=green]
              > > What is the point of having constructors on interfaces? They can't have
              > > data, so what is there to construct? You may mean abstract constructors,[/color][/color]
              but[color=blue][color=green]
              > > it would offer no benefit, since they could never be accessed though the
              > > interface reference, only through the implementation class.
              > >
              > > Statics is another issue.[/color]
              >
              > Not the way I'd considered it: these wouldn't be static methods with
              > implementations , they would be "abstract static" methods - very similar
              > to constructors. Basically it would ensure that implementors had the
              > appropriate constructors/static methods so that they could be called by
              > reflection. You'd still lose compile-time safety in the calling, but at
              > least implementors could get a compile-time error if they forgot to
              > implement the appropriate method/constructor. So yes, they *would*
              > offer a benefit.
              >[color=green]
              > > And constants.[/color]
              >
              > I don't see why they should go in interfaces particularly.
              >[color=green]
              > > And type declarations.[/color]
              >
              > Nor those.
              >
              > --
              > Jon Skeet - <skeet@pobox.co m>
              > http://www.pobox.com/~skeet/
              > If replying to the group, please do not mail me too[/color]


              Comment

              • Jon Skeet

                #8
                Re: C# language feature proposal

                Richard Cook <rpcee@msn.co m> wrote:[color=blue]
                > presumably statics and constructors in interfaces would be non-CLS
                > compliant, so these would have to be ignored by languages that don't
                > understand them.[/color]

                Mmm... that would be a pain.
                [color=blue]
                > Explicit implementation would also be illegal?
                >
                > Still fail to see any real benefit; it doesn't enhance "interface based
                > programming". It doesn't as far as I understand make a difference to any
                > actual code. If it's mainly used for instantiation, for plugins etc, you
                > won't get far if instantiation fails; I guess the application can't even
                > assume the plugin class even implements the required i/f. Is there an
                > enlightening example anywhere?[/color]

                It doesn't change the actual plug-in code at all, no - what it *does*
                mean is that the plug-in developer would get a compile-time error if
                they got things wrong. That's all it would give, but maybe that's
                enough.

                As Nick Paldino has said, it's a shame there's not a good way to do the
                other half of the problem - but with your first point here, that would
                be a pain too...

                --
                Jon Skeet - <skeet@pobox.co m>
                Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                If replying to the group, please do not mail me too

                Comment

                • Jasper Kent

                  #9
                  Re: C# language feature proposal

                  I see what you mean about requiring statics to be defined in derived classes
                  so that they can be called by reflection. Sounds to me the sort of thing
                  that one would do in C++ with templates - and you'd get compile time
                  checking too. Maybe Generics will give us this.

                  Jasper Kent

                  "Jon Skeet" <skeet@pobox.co m> wrote in message
                  news:MPG.19bf91 e9eafffc2f98a48 3@news.microsof t.com...[color=blue]
                  > Richard Cook <rpcee@msn.co m> wrote:[color=green]
                  > > presumably statics and constructors in interfaces would be non-CLS
                  > > compliant, so these would have to be ignored by languages that don't
                  > > understand them.[/color]
                  >
                  > Mmm... that would be a pain.
                  >[color=green]
                  > > Explicit implementation would also be illegal?
                  > >
                  > > Still fail to see any real benefit; it doesn't enhance "interface based
                  > > programming". It doesn't as far as I understand make a difference to any
                  > > actual code. If it's mainly used for instantiation, for plugins etc, you
                  > > won't get far if instantiation fails; I guess the application can't even
                  > > assume the plugin class even implements the required i/f. Is there an
                  > > enlightening example anywhere?[/color]
                  >
                  > It doesn't change the actual plug-in code at all, no - what it *does*
                  > mean is that the plug-in developer would get a compile-time error if
                  > they got things wrong. That's all it would give, but maybe that's
                  > enough.
                  >
                  > As Nick Paldino has said, it's a shame there's not a good way to do the
                  > other half of the problem - but with your first point here, that would
                  > be a pain too...
                  >
                  > --
                  > Jon Skeet - <skeet@pobox.co m>
                  > http://www.pobox.com/~skeet/
                  > If replying to the group, please do not mail me too[/color]


                  Comment

                  • Jon Skeet

                    #10
                    Re: C# language feature proposal

                    Jasper Kent <jasper_kent@ho tmail.com> wrote:[color=blue]
                    > I see what you mean about requiring statics to be defined in derived classes
                    > so that they can be called by reflection. Sounds to me the sort of thing
                    > that one would do in C++ with templates - and you'd get compile time
                    > checking too. Maybe Generics will give us this.[/color]

                    I can't see how generics will help in this regard, to be honest.

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                    If replying to the group, please do not mail me too

                    Comment

                    • Daniel O'Connell

                      #11
                      Re: C# language feature proposal


                      "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
                      news:OzVyc%23fc DHA.1656@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                      > The term 'abstract constructor' is a bit like 'clockwork orange'. It's[/color]
                      easy[color=blue]
                      > enough to stick the two words together, but that doesn't mean you've[/color]
                      created[color=blue]
                      > a coherent concept.
                      >[/color]

                      Its simply a selection of words. The goal is basically to require an
                      interface implementer to have to implement a given constructor. It would be
                      an enhancement to loosely knitted modular or plugin designs.
                      Although i can't think of one off hand, there are a couple interfaces in the
                      framework that are expected to have a given constructor. There is no way to
                      enforce it at compile-time, the interface class would simply not launch
                      properly.
                      I however don't agree with placing constructor, static method, or any other
                      kind of requirements in an interface, as I feel that *most* code that uses
                      the interface has no interest in the constructors, static methods, etc
                      required to create and\or manage the interfaces implementing type.
                      On the other hand, I clearly see the point in having a method of declaring a
                      set of interfaces, attributes, constructors, and base class a given type
                      must implement (not inherit, note the difference). Every project I do
                      involves more and more reflection. Most work I do now uses interfaces to
                      bind things together leaving the actual implementation hidden, often times
                      allowing for the specific implementation to be defined in a config file. And
                      for each project I end up writing atleast one loader class, each class being
                      pretty un-reusable because of because of the intricacies involved in the
                      construction of each different type. A generic loader class could be
                      designed, but I suspect that eventually I'd find problems that wouldn't work
                      and have to change my generic class, hopefully not breaking any other client
                      using it, or if i covered all bases it would likely require almost as much
                      work as the equivilent reflection code.
                      After thinking all those things through, I keep coming back to the same
                      idea. Namely an additional, for lack of a better term, base type(ie class,
                      interface, struct) that specifies class requirements. Something that can say
                      this class must implement interface A, B, and C. That there must be a
                      constructor with the signature (string name), that attribute X must be
                      defined on the class, that attribute Y should not be defined, that attribute
                      Z must be defined on method Bar, or that static method void Foo(int x)
                      should exist on the implementing type. The type would work something like an
                      interface, instead of providing implementation or providing and interface
                      into that implementation, it would instead provide a package of requirements
                      the system needs to create the implementing instance.
                      Much of this can be solved with an abstract class, however there are
                      problems with that. They cannot define required attributes, static methods
                      and constructors don't inherit nor can they be abstract(as you pointed out),
                      target classes couldn't derive from classes they may need to(assuming no
                      base class is specified, of course), modules couldn't provide two sets of
                      requirements, as one base class would provide one set of requirements, plus
                      other various minor issues.
                      It could also be argued that introducing a new base type makes no sense and
                      interface should simply be beefed up to support whats needed. However, like
                      I mentioned above, most code that uses interfaces doesn't actually care
                      about how it was created, what needs to be done to safely unload it, or
                      anything of that matter, that is the responsibility of the loading system.
                      Providing that level of information to a client is unnessecery.
                      Of course, adding a new base type would add quite a bit of complexity to the
                      language and I'm sure it would cause a number of problems I've not even
                      begun to think up. It is still the only way i've been able to think of that
                      provides compile time and runtime verification, and if the compiler was
                      written properly, could help developers avoid a considerable amount of
                      reflection code.

                      Ahh well, just my 5am musings. (btw, there is another comment further down,
                      ;)
                      [color=blue]
                      > By statics, I didn't mean abstracts statics (because they are clockwork
                      > oranges too) but static data and methods in the interface. Structurally it
                      > would be a matter of style whether these go in an interface or a separate
                      > helper class, but the point is they don't detract from an interface being[/color]
                      an[color=blue]
                      > interface. They fact they are in the interface is just a scoping issue. As[/color]
                      I[color=blue]
                      > said, it's a separate issue, though personally, I wouldn't allow them in
                      > interfaces.
                      >
                      > Java does allow constants in interfaces. Again, like statics, they don't
                      > hurt. However, I guess the reason that Java allows constants is that it
                      > doesn't have enums (Boo! Hiss!), and the fact that enums (and all type
                      > declarations) are not allowed in interfaces in C# is the real problem.
                      >
                      > In C# we might define a method in an interface which returns (or takes as[/color]
                      a[color=blue]
                      > parameter) and enum. For examples IChessBoard.Val idateMove (...) could
                      > return an enum of {GOOD,ILLEGAL,C HECK,CHECKMATE} . The return type is part[/color]
                      of[color=blue]
                      > the interface so it would be nice if it could be declared in there. The[/color]
                      same[color=blue]
                      > goes for other type declarations (i.e. classes and structs).
                      > IChessBoard.Get PieceAt (...) needs to returns a pair of piece type and
                      > colour (either as a struct or a class). This is best defined in the
                      > IChessBoard interface. Type declarations (for which no instances are
                      > declared) carry no data and hence don't break any of the rules of
                      > interfaces.
                      >[/color]

                      In this case, an associated enum is just as easy, as you imply. However I
                      take issue with most enums and classes declared within the scope of another
                      type, I seem to find issues where the contained class\enum is useful
                      somewhere else but the containing class makes it feel very absurdly placed.
                      I personally only think a class should be internal to another when there is
                      good reason to, perhaps because they interact in some manner inappropriate
                      or impossible in other situations, not simply because they make sense
                      together.
                      I also don't think an enum should ever be within the scope of another type.
                      [color=blue]
                      > Really it's all just a scoping issue. The question is (and there's[/color]
                      probably[color=blue]
                      > a good answer) why can't an interface be used to define it's own[/color]
                      namespace?[color=blue]
                      >
                      > Obviously all these are MSIL issues, not pure C# issues.
                      >
                      > Regards,
                      >
                      > Jasper Kent.
                      >
                      > "Daniel O'Connell" <onyxkirx@comca st.net> wrote in message
                      > news:vvZ4b.2517 45$It4.119395@r wcrnsc51.ops.as p.att.net...[color=green]
                      > >
                      > > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
                      > > news:uC6jXNTcDH A.616@TK2MSFTNG P11.phx.gbl...[color=darkred]
                      > > > What is the point of having constructors on interfaces? They can't[/color][/color][/color]
                      have[color=blue][color=green][color=darkred]
                      > > > data, so what is there to construct? You may mean abstract[/color][/color][/color]
                      constructors,[color=blue][color=green]
                      > > but[color=darkred]
                      > > > it would offer no benefit, since they could never be accessed though[/color][/color][/color]
                      the[color=blue][color=green][color=darkred]
                      > > > interface reference, only through the implementation class.[/color]
                      > >
                      > > Abstract constructors is the idea, basically an attempt to define a[/color][/color]
                      method[color=blue][color=green]
                      > > to require a given class to have a given constructor (needed for some
                      > > patterns). I don't think this is something appropriate for an interface,
                      > > myself.
                      > >[color=darkred]
                      > > >
                      > > > Statics is another issue.[/color]
                      > >
                      > > Explicit statics defined on the interface have no point, just stick them[/color]
                      > in[color=green]
                      > > a class. Defining that a class requires the existance of a static has[/color][/color]
                      its[color=blue][color=green]
                      > > uses, but again isn't something an interface should do.[color=darkred]
                      > > >
                      > > > And constants.
                      > > >[/color]
                      > >
                      > > Why define a constant on an interface...tha ts what classes are for as[/color]
                      > well.[color=green]
                      > > If you want it associated with a specific interface, then a related[/color][/color]
                      class[color=blue][color=green]
                      > > makes more sense than adding such things directly to the interface.
                      > >[color=darkred]
                      > > > And type declarations.[/color]
                      > >
                      > > What do you mean?
                      > >[color=darkred]
                      > > >
                      > > > Regards,
                      > > >
                      > > > Jasper Kent.
                      > > > "Harkos" <harkos@uol.com .br> wrote in message
                      > > > news:OVGnzvHcDH A.2960@tk2msftn gp13.phx.gbl...
                      > > > > Although I have seen explanations for not allowing this, I agree[/color][/color][/color]
                      both[color=blue][color=green][color=darkred]
                      > > > would
                      > > > > be a good addition to the language.
                      > > > >
                      > > > > []'s,
                      > > > > Harkos
                      > > > >
                      > > > > "Jon Skeet" <skeet@pobox.co m> escreveu na mensagem
                      > > > > news:MPG.19b9c4 709e394d3098a43 4@news.microsof t.com...
                      > > > > > Merlin <jgarza@hotmail .com> wrote:
                      > > > > > > I believe that interfaces are one of the more useful
                      > > > > > > design constructs available in C#. However, there's one
                      > > > > > > thing that I feel is missing in them. I propose that
                      > > > > > > interfaces be expanded to allow the specification of
                      > > > > > > constructors. Admittedly, this makes things a bit
                      > > > > > > confusing in that seeing constructors in an interface
                      > > > > > > seems to imply that the interface itself can be
                      > > > > > > instantiated. But I don't believe that it would be
                      > > > > > > significantly worse than the similar situation with
                      > > > > > > methods. Often enough, a family of classes will be
                      > > > > > > derived from an interface that are designed to have the
                      > > > > > > same basic set of constructors.
                      > > > > >
                      > > > > > And likewise static methods. It's been discussed before :)
                      > > > > >
                      > > > > > --
                      > > > > > Jon Skeet - <skeet@pobox.co m>
                      > > > > > http://www.pobox.com/~skeet/
                      > > > > > If replying to the group, please do not mail me too
                      > > > >
                      > > > >
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Jasper Kent

                        #12
                        Re: C# language feature proposal

                        I see your points on declaring types in interfaces (or classes). It's
                        certainly not a show-stopper to declare them in an associated namespace.

                        On the other hand, the absence of 'friend' in C# will increase the need to
                        nest classes for encapsulation reasons.

                        Jasper Kent.


                        "Daniel O'Connell" <onyxkirx@comca st.net> wrote in message
                        news:Hej5b.2588 00$It4.122215@r wcrnsc51.ops.as p.att.net...[color=blue]
                        >
                        > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
                        > news:OzVyc%23fc DHA.1656@TK2MSF TNGP10.phx.gbl. ..[color=green]
                        > > The term 'abstract constructor' is a bit like 'clockwork orange'. It's[/color]
                        > easy[color=green]
                        > > enough to stick the two words together, but that doesn't mean you've[/color]
                        > created[color=green]
                        > > a coherent concept.
                        > >[/color]
                        >
                        > Its simply a selection of words. The goal is basically to require an
                        > interface implementer to have to implement a given constructor. It would[/color]
                        be[color=blue]
                        > an enhancement to loosely knitted modular or plugin designs.
                        > Although i can't think of one off hand, there are a couple interfaces in[/color]
                        the[color=blue]
                        > framework that are expected to have a given constructor. There is no way[/color]
                        to[color=blue]
                        > enforce it at compile-time, the interface class would simply not launch
                        > properly.
                        > I however don't agree with placing constructor, static method, or any[/color]
                        other[color=blue]
                        > kind of requirements in an interface, as I feel that *most* code that uses
                        > the interface has no interest in the constructors, static methods, etc
                        > required to create and\or manage the interfaces implementing type.
                        > On the other hand, I clearly see the point in having a method of declaring[/color]
                        a[color=blue]
                        > set of interfaces, attributes, constructors, and base class a given type
                        > must implement (not inherit, note the difference). Every project I do
                        > involves more and more reflection. Most work I do now uses interfaces to
                        > bind things together leaving the actual implementation hidden, often times
                        > allowing for the specific implementation to be defined in a config file.[/color]
                        And[color=blue]
                        > for each project I end up writing atleast one loader class, each class[/color]
                        being[color=blue]
                        > pretty un-reusable because of because of the intricacies involved in the
                        > construction of each different type. A generic loader class could be
                        > designed, but I suspect that eventually I'd find problems that wouldn't[/color]
                        work[color=blue]
                        > and have to change my generic class, hopefully not breaking any other[/color]
                        client[color=blue]
                        > using it, or if i covered all bases it would likely require almost as much
                        > work as the equivilent reflection code.
                        > After thinking all those things through, I keep coming back to the same
                        > idea. Namely an additional, for lack of a better term, base type(ie class,
                        > interface, struct) that specifies class requirements. Something that can[/color]
                        say[color=blue]
                        > this class must implement interface A, B, and C. That there must be a
                        > constructor with the signature (string name), that attribute X must be
                        > defined on the class, that attribute Y should not be defined, that[/color]
                        attribute[color=blue]
                        > Z must be defined on method Bar, or that static method void Foo(int x)
                        > should exist on the implementing type. The type would work something like[/color]
                        an[color=blue]
                        > interface, instead of providing implementation or providing and interface
                        > into that implementation, it would instead provide a package of[/color]
                        requirements[color=blue]
                        > the system needs to create the implementing instance.
                        > Much of this can be solved with an abstract class, however there are
                        > problems with that. They cannot define required attributes, static methods
                        > and constructors don't inherit nor can they be abstract(as you pointed[/color]
                        out),[color=blue]
                        > target classes couldn't derive from classes they may need to(assuming no
                        > base class is specified, of course), modules couldn't provide two sets of
                        > requirements, as one base class would provide one set of requirements,[/color]
                        plus[color=blue]
                        > other various minor issues.
                        > It could also be argued that introducing a new base type makes no sense[/color]
                        and[color=blue]
                        > interface should simply be beefed up to support whats needed. However,[/color]
                        like[color=blue]
                        > I mentioned above, most code that uses interfaces doesn't actually care
                        > about how it was created, what needs to be done to safely unload it, or
                        > anything of that matter, that is the responsibility of the loading system.
                        > Providing that level of information to a client is unnessecery.
                        > Of course, adding a new base type would add quite a bit of complexity to[/color]
                        the[color=blue]
                        > language and I'm sure it would cause a number of problems I've not even
                        > begun to think up. It is still the only way i've been able to think of[/color]
                        that[color=blue]
                        > provides compile time and runtime verification, and if the compiler was
                        > written properly, could help developers avoid a considerable amount of
                        > reflection code.
                        >
                        > Ahh well, just my 5am musings. (btw, there is another comment further[/color]
                        down,[color=blue]
                        > ;)
                        >[color=green]
                        > > By statics, I didn't mean abstracts statics (because they are clockwork
                        > > oranges too) but static data and methods in the interface. Structurally[/color][/color]
                        it[color=blue][color=green]
                        > > would be a matter of style whether these go in an interface or a[/color][/color]
                        separate[color=blue][color=green]
                        > > helper class, but the point is they don't detract from an interface[/color][/color]
                        being[color=blue]
                        > an[color=green]
                        > > interface. They fact they are in the interface is just a scoping issue.[/color][/color]
                        As[color=blue]
                        > I[color=green]
                        > > said, it's a separate issue, though personally, I wouldn't allow them in
                        > > interfaces.
                        > >
                        > > Java does allow constants in interfaces. Again, like statics, they don't
                        > > hurt. However, I guess the reason that Java allows constants is that it
                        > > doesn't have enums (Boo! Hiss!), and the fact that enums (and all type
                        > > declarations) are not allowed in interfaces in C# is the real problem.
                        > >
                        > > In C# we might define a method in an interface which returns (or takes[/color][/color]
                        as[color=blue]
                        > a[color=green]
                        > > parameter) and enum. For examples IChessBoard.Val idateMove (...) could
                        > > return an enum of {GOOD,ILLEGAL,C HECK,CHECKMATE} . The return type is[/color][/color]
                        part[color=blue]
                        > of[color=green]
                        > > the interface so it would be nice if it could be declared in there. The[/color]
                        > same[color=green]
                        > > goes for other type declarations (i.e. classes and structs).
                        > > IChessBoard.Get PieceAt (...) needs to returns a pair of piece type and
                        > > colour (either as a struct or a class). This is best defined in the
                        > > IChessBoard interface. Type declarations (for which no instances are
                        > > declared) carry no data and hence don't break any of the rules of
                        > > interfaces.
                        > >[/color]
                        >
                        > In this case, an associated enum is just as easy, as you imply. However I
                        > take issue with most enums and classes declared within the scope of[/color]
                        another[color=blue]
                        > type, I seem to find issues where the contained class\enum is useful
                        > somewhere else but the containing class makes it feel very absurdly[/color]
                        placed.[color=blue]
                        > I personally only think a class should be internal to another when there[/color]
                        is[color=blue]
                        > good reason to, perhaps because they interact in some manner inappropriate
                        > or impossible in other situations, not simply because they make sense
                        > together.
                        > I also don't think an enum should ever be within the scope of another[/color]
                        type.[color=blue]
                        >[color=green]
                        > > Really it's all just a scoping issue. The question is (and there's[/color]
                        > probably[color=green]
                        > > a good answer) why can't an interface be used to define it's own[/color]
                        > namespace?[color=green]
                        > >
                        > > Obviously all these are MSIL issues, not pure C# issues.
                        > >
                        > > Regards,
                        > >
                        > > Jasper Kent.
                        > >
                        > > "Daniel O'Connell" <onyxkirx@comca st.net> wrote in message
                        > > news:vvZ4b.2517 45$It4.119395@r wcrnsc51.ops.as p.att.net...[color=darkred]
                        > > >
                        > > > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
                        > > > news:uC6jXNTcDH A.616@TK2MSFTNG P11.phx.gbl...
                        > > > > What is the point of having constructors on interfaces? They can't[/color][/color]
                        > have[color=green][color=darkred]
                        > > > > data, so what is there to construct? You may mean abstract[/color][/color]
                        > constructors,[color=green][color=darkred]
                        > > > but
                        > > > > it would offer no benefit, since they could never be accessed though[/color][/color]
                        > the[color=green][color=darkred]
                        > > > > interface reference, only through the implementation class.
                        > > >
                        > > > Abstract constructors is the idea, basically an attempt to define a[/color][/color]
                        > method[color=green][color=darkred]
                        > > > to require a given class to have a given constructor (needed for some
                        > > > patterns). I don't think this is something appropriate for an[/color][/color][/color]
                        interface,[color=blue][color=green][color=darkred]
                        > > > myself.
                        > > >
                        > > > >
                        > > > > Statics is another issue.
                        > > >
                        > > > Explicit statics defined on the interface have no point, just stick[/color][/color][/color]
                        them[color=blue][color=green]
                        > > in[color=darkred]
                        > > > a class. Defining that a class requires the existance of a static has[/color][/color]
                        > its[color=green][color=darkred]
                        > > > uses, but again isn't something an interface should do.
                        > > > >
                        > > > > And constants.
                        > > > >
                        > > >
                        > > > Why define a constant on an interface...tha ts what classes are for as[/color]
                        > > well.[color=darkred]
                        > > > If you want it associated with a specific interface, then a related[/color][/color]
                        > class[color=green][color=darkred]
                        > > > makes more sense than adding such things directly to the interface.
                        > > >
                        > > > > And type declarations.
                        > > >
                        > > > What do you mean?
                        > > >
                        > > > >
                        > > > > Regards,
                        > > > >
                        > > > > Jasper Kent.
                        > > > > "Harkos" <harkos@uol.com .br> wrote in message
                        > > > > news:OVGnzvHcDH A.2960@tk2msftn gp13.phx.gbl...
                        > > > > > Although I have seen explanations for not allowing this, I agree[/color][/color]
                        > both[color=green][color=darkred]
                        > > > > would
                        > > > > > be a good addition to the language.
                        > > > > >
                        > > > > > []'s,
                        > > > > > Harkos
                        > > > > >
                        > > > > > "Jon Skeet" <skeet@pobox.co m> escreveu na mensagem
                        > > > > > news:MPG.19b9c4 709e394d3098a43 4@news.microsof t.com...
                        > > > > > > Merlin <jgarza@hotmail .com> wrote:
                        > > > > > > > I believe that interfaces are one of the more useful
                        > > > > > > > design constructs available in C#. However, there's one
                        > > > > > > > thing that I feel is missing in them. I propose that
                        > > > > > > > interfaces be expanded to allow the specification of
                        > > > > > > > constructors. Admittedly, this makes things a bit
                        > > > > > > > confusing in that seeing constructors in an interface
                        > > > > > > > seems to imply that the interface itself can be
                        > > > > > > > instantiated. But I don't believe that it would be
                        > > > > > > > significantly worse than the similar situation with
                        > > > > > > > methods. Often enough, a family of classes will be
                        > > > > > > > derived from an interface that are designed to have the
                        > > > > > > > same basic set of constructors.
                        > > > > > >
                        > > > > > > And likewise static methods. It's been discussed before :)
                        > > > > > >
                        > > > > > > --
                        > > > > > > Jon Skeet - <skeet@pobox.co m>
                        > > > > > > http://www.pobox.com/~skeet/
                        > > > > > > If replying to the group, please do not mail me too
                        > > > > >
                        > > > > >
                        > > > >
                        > > > >
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Jasper Kent

                          #13
                          Re: C# language feature proposal

                          True enough, but:

                          1) As discussed elsewhere, this shouldn't really be declared as part of the
                          interface, because the constructor isn't called through virtual lookup. This
                          sort of thing (constructors and statics) could be enforced by some sore of
                          class requirements definition, but it would be a different thing from an
                          interface.

                          2) This particular feature of serialization in C# is not, IMHO, the greatest
                          bit of design. It seems to be somewhat overreliant on reflection. It would
                          seem more sensible to have an abstract Deserialize
                          (SerializationI nfo,StreamingCo ntext) and just construct with the default
                          constructor. Even that, however, requires that there is a default
                          constructor, which could only be determined at runtime. At least a default
                          constructor is more likely to exist than the serialization overload.

                          Oh how I miss C++ templates.

                          Jasper Kent.

                          "Wayne Citrin" <wcitrin@jnbrid ge.com> wrote in message
                          news:d0bd960.03 09030854.613172 27@posting.goog le.com...[color=blue]
                          > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message[/color]
                          news:<uC6jXNTcD HA.616@TK2MSFTN GP11.phx.gbl>.. .[color=blue][color=green]
                          > > What is the point of having constructors on interfaces? They can't have
                          > > data, so what is there to construct? You may mean abstract constructors,[/color][/color]
                          but[color=blue][color=green]
                          > > it would offer no benefit, since they could never be accessed though the
                          > > interface reference, only through the implementation class.
                          > >[/color]
                          >
                          > I can see at least one scenario where having constructors in
                          > interfaces would be useful. Classes implementing the ISerializable
                          > interface need to have the special deserializing constructor (the one
                          > that takes parameters of classes SerializationIn fo and
                          > StreamingContex t), but there's absolutely no way to enforce this at
                          > compile time. If you forget to include this constructor, the only way
                          > you'll discover it is at run time when deserialization fails. Much
                          > better to be able to discover this error at compile time.
                          >
                          > Wayne
                          > _______________ _______________ ______
                          >
                          > Wayne Citrin
                          > JNBridge, LLC
                          > citrin@jnbridge .com
                          > www.jnbridge.com
                          > Spanning the Worlds of Java and .NET
                          > _______________ _______________ ______[/color]


                          Comment

                          • Joshua Coady

                            #14
                            Re: C# language feature proposal

                            > Oh how I miss C++ templates.

                            I agree! Anyone know the latest on when we can expect a .Net release that
                            includes generics?

                            Josh


                            "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
                            news:OS79EDkcDH A.1884@TK2MSFTN GP10.phx.gbl...[color=blue]
                            > True enough, but:
                            >
                            > 1) As discussed elsewhere, this shouldn't really be declared as part of[/color]
                            the[color=blue]
                            > interface, because the constructor isn't called through virtual lookup.[/color]
                            This[color=blue]
                            > sort of thing (constructors and statics) could be enforced by some sore of
                            > class requirements definition, but it would be a different thing from an
                            > interface.
                            >
                            > 2) This particular feature of serialization in C# is not, IMHO, the[/color]
                            greatest[color=blue]
                            > bit of design. It seems to be somewhat overreliant on reflection. It would
                            > seem more sensible to have an abstract Deserialize
                            > (SerializationI nfo,StreamingCo ntext) and just construct with the default
                            > constructor. Even that, however, requires that there is a default
                            > constructor, which could only be determined at runtime. At least a default
                            > constructor is more likely to exist than the serialization overload.
                            >
                            > Oh how I miss C++ templates.
                            >
                            > Jasper Kent.
                            >
                            > "Wayne Citrin" <wcitrin@jnbrid ge.com> wrote in message
                            > news:d0bd960.03 09030854.613172 27@posting.goog le.com...[color=green]
                            > > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message[/color]
                            > news:<uC6jXNTcD HA.616@TK2MSFTN GP11.phx.gbl>.. .[color=green][color=darkred]
                            > > > What is the point of having constructors on interfaces? They can't[/color][/color][/color]
                            have[color=blue][color=green][color=darkred]
                            > > > data, so what is there to construct? You may mean abstract[/color][/color][/color]
                            constructors,[color=blue]
                            > but[color=green][color=darkred]
                            > > > it would offer no benefit, since they could never be accessed though[/color][/color][/color]
                            the[color=blue][color=green][color=darkred]
                            > > > interface reference, only through the implementation class.
                            > > >[/color]
                            > >
                            > > I can see at least one scenario where having constructors in
                            > > interfaces would be useful. Classes implementing the ISerializable
                            > > interface need to have the special deserializing constructor (the one
                            > > that takes parameters of classes SerializationIn fo and
                            > > StreamingContex t), but there's absolutely no way to enforce this at
                            > > compile time. If you forget to include this constructor, the only way
                            > > you'll discover it is at run time when deserialization fails. Much
                            > > better to be able to discover this error at compile time.
                            > >
                            > > Wayne
                            > > _______________ _______________ ______
                            > >
                            > > Wayne Citrin
                            > > JNBridge, LLC
                            > > citrin@jnbridge .com
                            > > www.jnbridge.com
                            > > Spanning the Worlds of Java and .NET
                            > > _______________ _______________ ______[/color]
                            >
                            >[/color]


                            Comment

                            • Chad Myers

                              #15
                              Re: C# language feature proposal

                              ..NET 2.0.

                              Here are the other features:


                              If you want to try generics today, you can
                              use the Gyro version of the Rotor .NET SSCLI:
                              Explore research at Microsoft, a site featuring the impact of research along with publications, products, downloads, and research careers.


                              -c

                              "Joshua Coady" <josh@coady.u s> wrote in message
                              news:e3tBHakcDH A.3068@TK2MSFTN GP11.phx.gbl...[color=blue][color=green]
                              > > Oh how I miss C++ templates.[/color]
                              >
                              > I agree! Anyone know the latest on when we can expect a .Net release[/color]
                              that[color=blue]
                              > includes generics?
                              >
                              > Josh
                              >
                              >
                              > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
                              > news:OS79EDkcDH A.1884@TK2MSFTN GP10.phx.gbl...[color=green]
                              > > True enough, but:
                              > >
                              > > 1) As discussed elsewhere, this shouldn't really be declared as part[/color][/color]
                              of[color=blue]
                              > the[color=green]
                              > > interface, because the constructor isn't called through virtual[/color][/color]
                              lookup.[color=blue]
                              > This[color=green]
                              > > sort of thing (constructors and statics) could be enforced by some[/color][/color]
                              sore of[color=blue][color=green]
                              > > class requirements definition, but it would be a different thing[/color][/color]
                              from an[color=blue][color=green]
                              > > interface.
                              > >
                              > > 2) This particular feature of serialization in C# is not, IMHO, the[/color]
                              > greatest[color=green]
                              > > bit of design. It seems to be somewhat overreliant on reflection. It[/color][/color]
                              would[color=blue][color=green]
                              > > seem more sensible to have an abstract Deserialize
                              > > (SerializationI nfo,StreamingCo ntext) and just construct with the[/color][/color]
                              default[color=blue][color=green]
                              > > constructor. Even that, however, requires that there is a default
                              > > constructor, which could only be determined at runtime. At least a[/color][/color]
                              default[color=blue][color=green]
                              > > constructor is more likely to exist than the serialization overload.
                              > >
                              > > Oh how I miss C++ templates.
                              > >
                              > > Jasper Kent.
                              > >
                              > > "Wayne Citrin" <wcitrin@jnbrid ge.com> wrote in message
                              > > news:d0bd960.03 09030854.613172 27@posting.goog le.com...[color=darkred]
                              > > > "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message[/color]
                              > > news:<uC6jXNTcD HA.616@TK2MSFTN GP11.phx.gbl>.. .[color=darkred]
                              > > > > What is the point of having constructors on interfaces? They[/color][/color][/color]
                              can't[color=blue]
                              > have[color=green][color=darkred]
                              > > > > data, so what is there to construct? You may mean abstract[/color][/color]
                              > constructors,[color=green]
                              > > but[color=darkred]
                              > > > > it would offer no benefit, since they could never be accessed[/color][/color][/color]
                              though[color=blue]
                              > the[color=green][color=darkred]
                              > > > > interface reference, only through the implementation class.
                              > > > >
                              > > >
                              > > > I can see at least one scenario where having constructors in
                              > > > interfaces would be useful. Classes implementing the[/color][/color][/color]
                              ISerializable[color=blue][color=green][color=darkred]
                              > > > interface need to have the special deserializing constructor (the[/color][/color][/color]
                              one[color=blue][color=green][color=darkred]
                              > > > that takes parameters of classes SerializationIn fo and
                              > > > StreamingContex t), but there's absolutely no way to enforce this[/color][/color][/color]
                              at[color=blue][color=green][color=darkred]
                              > > > compile time. If you forget to include this constructor, the only[/color][/color][/color]
                              way[color=blue][color=green][color=darkred]
                              > > > you'll discover it is at run time when deserialization fails.[/color][/color][/color]
                              Much[color=blue][color=green][color=darkred]
                              > > > better to be able to discover this error at compile time.
                              > > >
                              > > > Wayne
                              > > > _______________ _______________ ______
                              > > >
                              > > > Wayne Citrin
                              > > > JNBridge, LLC
                              > > > citrin@jnbridge .com
                              > > > www.jnbridge.com
                              > > > Spanning the Worlds of Java and .NET
                              > > > _______________ _______________ ______[/color]
                              > >
                              > >[/color]
                              >
                              >[/color]


                              Comment

                              Working...