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. The Lounge
  3. C# 2.0 Why stop at partial interfaces?

C# 2.0 Why stop at partial interfaces?

Scheduled Pinned Locked Moved The Lounge
csharpvisual-studioquestion
11 Posts 5 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.
  • J Jim Bennett

    Does anyone here plan on using the new "partial" keyword for their own C# class libraries? Seems like it was a plug for the Visual Studio Designer and it made its way to partial interfaces and structs as well :sigh: Jim

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    Jim Bennett wrote:

    Does anyone here plan on using the new "partial" keyword for their own C# class libraries?

    So that your library can be extended by a user ? I'd expect not, surely ? Christian Graus - Microsoft MVP - C++

    J 1 Reply Last reply
    0
    • C Christian Graus

      Jim Bennett wrote:

      Does anyone here plan on using the new "partial" keyword for their own C# class libraries?

      So that your library can be extended by a user ? I'd expect not, surely ? Christian Graus - Microsoft MVP - C++

      J Offline
      J Offline
      Jim Bennett
      wrote on last edited by
      #3

      I like my users, so I would never throw partial types at them :-D Jim

      1 Reply Last reply
      0
      • J Jim Bennett

        Does anyone here plan on using the new "partial" keyword for their own C# class libraries? Seems like it was a plug for the Visual Studio Designer and it made its way to partial interfaces and structs as well :sigh: Jim

        L Offline
        L Offline
        Leslie Sanford
        wrote on last edited by
        #4

        Jim Bennett wrote:

        Does anyone here plan on using the new "partial" keyword for their own C# class libraries?

        I'm a big fan of using private classes for delegating class responsibilities. I used these a lot in my C++ days but shyed away from them in C# because the private class had to share the same source file as its parent class. So while I still used them when appropriate, I felt I was adding to a source file's code bloat, so I would look for other solutions, such as making a helper class internal. With the partial feature, I'll probably return to using them more often and relying less on the internal feature as a way of factoring out class functionality that should remain private to a class. Also, the partial feature will make home grown code generation easier, in my opinion. You factor out the code generated parts of a class to its own source file using the partial feature. If you need to regenerate the code, you don't have to worry about stepping on the hand coded parts of the class. Just regenerate the source file with the code generated parts, and you're on your way. So yeah, I'll probably use the partial feature. :)

        J 1 Reply Last reply
        0
        • L Leslie Sanford

          Jim Bennett wrote:

          Does anyone here plan on using the new "partial" keyword for their own C# class libraries?

          I'm a big fan of using private classes for delegating class responsibilities. I used these a lot in my C++ days but shyed away from them in C# because the private class had to share the same source file as its parent class. So while I still used them when appropriate, I felt I was adding to a source file's code bloat, so I would look for other solutions, such as making a helper class internal. With the partial feature, I'll probably return to using them more often and relying less on the internal feature as a way of factoring out class functionality that should remain private to a class. Also, the partial feature will make home grown code generation easier, in my opinion. You factor out the code generated parts of a class to its own source file using the partial feature. If you need to regenerate the code, you don't have to worry about stepping on the hand coded parts of the class. Just regenerate the source file with the code generated parts, and you're on your way. So yeah, I'll probably use the partial feature. :)

          J Offline
          J Offline
          Jim Bennett
          wrote on last edited by
          #5

          I see your point on using partial classes to hide the private class implementation from the public section so you can move away from private classes. And yes, generated code should be hidden from view at all times too:) Jim

          1 Reply Last reply
          0
          • J Jim Bennett

            Does anyone here plan on using the new "partial" keyword for their own C# class libraries? Seems like it was a plug for the Visual Studio Designer and it made its way to partial interfaces and structs as well :sigh: Jim

            C Offline
            C Offline
            Chris Maunder
            wrote on last edited by
            #6

            I originally thought I'd be using them to keep file sizes managable, but I've gone off the idea. If a class is that big that it needs to be split into several files, then it probably needs to be split into several classes as well. cheers Chris Maunder

            C L J 3 Replies Last reply
            0
            • C Chris Maunder

              I originally thought I'd be using them to keep file sizes managable, but I've gone off the idea. If a class is that big that it needs to be split into several files, then it probably needs to be split into several classes as well. cheers Chris Maunder

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #7

              Yeah, I agree. The best use IMO is to keep the auto generated stuff out of our faces. Christian Graus - Microsoft MVP - C++

              R 1 Reply Last reply
              0
              • C Chris Maunder

                I originally thought I'd be using them to keep file sizes managable, but I've gone off the idea. If a class is that big that it needs to be split into several files, then it probably needs to be split into several classes as well. cheers Chris Maunder

                L Offline
                L Offline
                Leslie Sanford
                wrote on last edited by
                #8

                Chris Maunder wrote:

                I originally thought I'd be using them to keep file sizes managable, but I've gone off the idea. If a class is that big that it needs to be split into several files, then it probably needs to be split into several classes as well.

                I kind of agree with this, but I wonder... Say you have a class that has a well-defined set of responsibilities. It implements several interfaces, for example, IComponent, IDisposable (included with IComponent), and ISynchronizeInvoke. Each one of these interfaces is pretty small by themselves, but together they add up to a fair number of properties and methods. Then you have the class's own fields, events, properties, constructors, methods, and even a class that is nicely grained in the context of a library takes a pretty good chunk of source code to implement. With such a class, it's not always obvious how to factor out parts of it into classes. So maybe the partial feature would be nice way to factor out each interface implementation into its own source file. This would seem to be a good division point. Currently, we use Visual Studio to segragate each interface implementation with regions, so why not go a step further with the partial feature? It might make the size of source files more managable. This could be taken to an extreme and abused, of course, but if used wisely, it might be something to consider. Many classes are pretty simple, while others are more like components in that they offer a comprehensive set of services. Components can be made up of other classes, many times private (see my earlier post to this thread), and often implement several interfaces. I think these types of classes that represent larger building blocks within an application or library are key candidates for the partial feature. At least I look forward to taking that approach. After gaining some insight from actually using the feature, I may change my mind about it or have a different take. We'll see.

                J 1 Reply Last reply
                0
                • C Christian Graus

                  Yeah, I agree. The best use IMO is to keep the auto generated stuff out of our faces. Christian Graus - Microsoft MVP - C++

                  R Offline
                  R Offline
                  Roger Alsing 0
                  wrote on last edited by
                  #9

                  Ive got the same impression , that you should use partial for splitting user code from autogen code. so that one file can be regenerated and the other is still intact. and maybe maybe to separate some interface implementations from the rest of the code

                  1 Reply Last reply
                  0
                  • L Leslie Sanford

                    Chris Maunder wrote:

                    I originally thought I'd be using them to keep file sizes managable, but I've gone off the idea. If a class is that big that it needs to be split into several files, then it probably needs to be split into several classes as well.

                    I kind of agree with this, but I wonder... Say you have a class that has a well-defined set of responsibilities. It implements several interfaces, for example, IComponent, IDisposable (included with IComponent), and ISynchronizeInvoke. Each one of these interfaces is pretty small by themselves, but together they add up to a fair number of properties and methods. Then you have the class's own fields, events, properties, constructors, methods, and even a class that is nicely grained in the context of a library takes a pretty good chunk of source code to implement. With such a class, it's not always obvious how to factor out parts of it into classes. So maybe the partial feature would be nice way to factor out each interface implementation into its own source file. This would seem to be a good division point. Currently, we use Visual Studio to segragate each interface implementation with regions, so why not go a step further with the partial feature? It might make the size of source files more managable. This could be taken to an extreme and abused, of course, but if used wisely, it might be something to consider. Many classes are pretty simple, while others are more like components in that they offer a comprehensive set of services. Components can be made up of other classes, many times private (see my earlier post to this thread), and often implement several interfaces. I think these types of classes that represent larger building blocks within an application or library are key candidates for the partial feature. At least I look forward to taking that approach. After gaining some insight from actually using the feature, I may change my mind about it or have a different take. We'll see.

                    J Offline
                    J Offline
                    Jim Bennett
                    wrote on last edited by
                    #10

                    Leslie Sanford wrote:

                    it's not always obvious how to factor out parts of it into classes. So maybe the partial feature would be nice way to factor out each interface implementation into its own source file.

                    You could also say that whenever you face this choice of division with interface implementations you could make a run at creating new classes (rather than use the partial class technique) and see how it works out with those classes:) Jim

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      I originally thought I'd be using them to keep file sizes managable, but I've gone off the idea. If a class is that big that it needs to be split into several files, then it probably needs to be split into several classes as well. cheers Chris Maunder

                      J Offline
                      J Offline
                      Jim Bennett
                      wrote on last edited by
                      #11

                      Hey Chris, Well said! Jim

                      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