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. Acceptability of C# Partial Classes

Acceptability of C# Partial Classes

Scheduled Pinned Locked Moved The Lounge
csharpdatabaseregex
15 Posts 9 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.
  • C Clifford Nelson

    I have heard people say that only use partial classes when there is auto-generated code. I have found that I like to use them to separate different parts of the code that are pretty much independent, but not totally. It seems to make working on the code easier since functionality is separated by files, and this reduces the length of each file, which makes it easy to find what I am looking. If I created separate classes for the same thing, I would need to pass information to allow them to change access elements. I have also used, but did not implement, a case in an adapter where all the calls to get database data were through the same class, and each table had its own file which was a partial class. I thought this worked well, and kept code conflicts down. I just followed the pattern.

    B Offline
    B Offline
    Brisingr Aerowing
    wrote on last edited by
    #2

    I do the same thing.

    What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

    1 Reply Last reply
    0
    • C Clifford Nelson

      I have heard people say that only use partial classes when there is auto-generated code. I have found that I like to use them to separate different parts of the code that are pretty much independent, but not totally. It seems to make working on the code easier since functionality is separated by files, and this reduces the length of each file, which makes it easy to find what I am looking. If I created separate classes for the same thing, I would need to pass information to allow them to change access elements. I have also used, but did not implement, a case in an adapter where all the calls to get database data were through the same class, and each table had its own file which was a partial class. I thought this worked well, and kept code conflicts down. I just followed the pattern.

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #3

      Clifford Nelson wrote:

      It seems to make working on the code easier since functionality is separated by files,

      I do the same thing if a class has a large number of methods, but this is quite rare. In most cases, my top level facade class will expose a number (e.g. half a dozen) of services, each of which offer specific functionality.  This allows me to swap/evolve service provider implementations over time.  This pattern has proved useful when maintaining this[^] app over several versions. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      S B 2 Replies Last reply
      0
      • R Ravi Bhavnani

        Clifford Nelson wrote:

        It seems to make working on the code easier since functionality is separated by files,

        I do the same thing if a class has a large number of methods, but this is quite rare. In most cases, my top level facade class will expose a number (e.g. half a dozen) of services, each of which offer specific functionality.  This allows me to swap/evolve service provider implementations over time.  This pattern has proved useful when maintaining this[^] app over several versions. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        S Offline
        S Offline
        Slacker007
        wrote on last edited by
        #4

        Anything for self-promotion. Ever the salesman. :sigh: :-D

        R 1 Reply Last reply
        0
        • S Slacker007

          Anything for self-promotion. Ever the salesman. :sigh: :-D

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #5

          But it's true. :^) Maintaining a fairly large app (with a large active user base) over 12+ years is no easy feat.  I need the benefit of a carefully thought out design to help me do that.  I was just sharing my experience. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          S 1 Reply Last reply
          0
          • R Ravi Bhavnani

            Clifford Nelson wrote:

            It seems to make working on the code easier since functionality is separated by files,

            I do the same thing if a class has a large number of methods, but this is quite rare. In most cases, my top level facade class will expose a number (e.g. half a dozen) of services, each of which offer specific functionality.  This allows me to swap/evolve service provider implementations over time.  This pattern has proved useful when maintaining this[^] app over several versions. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #6

            Hi Ravi-ji, Assuming you have not published in depth about this strategy for app structure, I'd really appreciate seeing an article by you on this. cheers, Bill

            «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

            R 1 Reply Last reply
            0
            • C Clifford Nelson

              I have heard people say that only use partial classes when there is auto-generated code. I have found that I like to use them to separate different parts of the code that are pretty much independent, but not totally. It seems to make working on the code easier since functionality is separated by files, and this reduces the length of each file, which makes it easy to find what I am looking. If I created separate classes for the same thing, I would need to pass information to allow them to change access elements. I have also used, but did not implement, a case in an adapter where all the calls to get database data were through the same class, and each table had its own file which was a partial class. I thought this worked well, and kept code conflicts down. I just followed the pattern.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #7

              I use them extensively. Particularly for library routines. .net 1 should not have been released without them.

              1 Reply Last reply
              0
              • C Clifford Nelson

                I have heard people say that only use partial classes when there is auto-generated code. I have found that I like to use them to separate different parts of the code that are pretty much independent, but not totally. It seems to make working on the code easier since functionality is separated by files, and this reduces the length of each file, which makes it easy to find what I am looking. If I created separate classes for the same thing, I would need to pass information to allow them to change access elements. I have also used, but did not implement, a case in an adapter where all the calls to get database data were through the same class, and each table had its own file which was a partial class. I thought this worked well, and kept code conflicts down. I just followed the pattern.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #8

                Never having used one I now see an immediate use for them. I have a dashboard with multiple tabs, all the data is related but I got annoyed by the size of the code base and split the 3rd tab out to a UC. Now I see I should have create a partial class.

                Never underestimate the power of human stupidity RAH

                C 1 Reply Last reply
                0
                • R Ravi Bhavnani

                  But it's true. :^) Maintaining a fairly large app (with a large active user base) over 12+ years is no easy feat.  I need the benefit of a carefully thought out design to help me do that.  I was just sharing my experience. /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  S Offline
                  S Offline
                  Slacker007
                  wrote on last edited by
                  #9

                  I was just teasing you, Ravi. I agree with your comments on the topic. :)

                  1 Reply Last reply
                  0
                  • C Clifford Nelson

                    I have heard people say that only use partial classes when there is auto-generated code. I have found that I like to use them to separate different parts of the code that are pretty much independent, but not totally. It seems to make working on the code easier since functionality is separated by files, and this reduces the length of each file, which makes it easy to find what I am looking. If I created separate classes for the same thing, I would need to pass information to allow them to change access elements. I have also used, but did not implement, a case in an adapter where all the calls to get database data were through the same class, and each table had its own file which was a partial class. I thought this worked well, and kept code conflicts down. I just followed the pattern.

                    J Offline
                    J Offline
                    Jorgen Andersson
                    wrote on last edited by
                    #10

                    Partial classes is a good thing, but like anything it can be abused. I have inherited an application with thousands of partial classes spread over just a few files partitioned by funtionality. If I ever meet the programmer I'll teach him generics with a drill and a cactus.

                    Wrong is evil and must be defeated. - Jeff Ello

                    1 Reply Last reply
                    0
                    • C Clifford Nelson

                      I have heard people say that only use partial classes when there is auto-generated code. I have found that I like to use them to separate different parts of the code that are pretty much independent, but not totally. It seems to make working on the code easier since functionality is separated by files, and this reduces the length of each file, which makes it easy to find what I am looking. If I created separate classes for the same thing, I would need to pass information to allow them to change access elements. I have also used, but did not implement, a case in an adapter where all the calls to get database data were through the same class, and each table had its own file which was a partial class. I thought this worked well, and kept code conflicts down. I just followed the pattern.

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #11

                      For a particular WinForm app, I have a lot of controls on the main page. I use partial classes to break up the handling of the control events into their logical groups. Otherwise, I never use partial classes, and instead use a publisher/subscriber pattern to communicate between instances, which also has the advantages of: 1) letting me hook in logging so I can see what the heck is going on 2) process intercommunication asynchronously, as the pub/sub I use can make message handler call on a separate thread 3) better exception handling, as the pub/sub will wrap the message handler call in a try-catch and log exceptions 4) because the exception handler uses the pub/sub itself to log the exception, I get can wire up other services, like an email notification, when errors occur 5) and the pub/sub instantiates the receiver class, so I'm enforcing completely isolated processing, which is great for thread safety. So effectively, all the things that actually do non-UI things become services, and I often write them as runtime loaded modules that register themselves in the pub/sub, which is cool because I can then easily mock the services, change the business logic by loading a different module that implements different behaviors, extend the behaviors simply by adding new modules that handle the same messages, and so forth. So there, in a nutshell, you have The Clifton Method[^]. Marc

                      Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

                      1 Reply Last reply
                      0
                      • B BillWoodruff

                        Hi Ravi-ji, Assuming you have not published in depth about this strategy for app structure, I'd really appreciate seeing an article by you on this. cheers, Bill

                        «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

                        R Offline
                        R Offline
                        Ravi Bhavnani
                        wrote on last edited by
                        #12

                        Dunno if it's worthy of an article, Bill-ji.  Maybe a tip, at best? It isn't something I designed - just a pattern I employ.  But I'll tipify it if you think it's worth doing. /ravi

                        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                        B 1 Reply Last reply
                        0
                        • R Ravi Bhavnani

                          Dunno if it's worthy of an article, Bill-ji.  Maybe a tip, at best? It isn't something I designed - just a pattern I employ.  But I'll tipify it if you think it's worth doing. /ravi

                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                          B Offline
                          B Offline
                          BillWoodruff
                          wrote on last edited by
                          #13

                          Sukria, I accept tips :) cheers, Bill

                          «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

                          R 1 Reply Last reply
                          0
                          • B BillWoodruff

                            Sukria, I accept tips :) cheers, Bill

                            «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

                            R Offline
                            R Offline
                            Ravi Bhavnani
                            wrote on last edited by
                            #14

                            OK. But you're giving me more credit for my knowledge of Hindi (and software engineering) than I'm due. :) /ravi

                            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                            1 Reply Last reply
                            0
                            • M Mycroft Holmes

                              Never having used one I now see an immediate use for them. I have a dashboard with multiple tabs, all the data is related but I got annoyed by the size of the code base and split the 3rd tab out to a UC. Now I see I should have create a partial class.

                              Never underestimate the power of human stupidity RAH

                              C Offline
                              C Offline
                              Clifford Nelson
                              wrote on last edited by
                              #15

                              Usually when I have tabs I split out into separate classes, but partial classes seems like I good option

                              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