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. General Programming
  3. C#
  4. What is good practice

What is good practice

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 1 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.
  • U Offline
    U Offline
    User 13482557
    wrote on last edited by
    #1

    I have written a program the has numerous methods in form1.cs file and it has become somewhat difficult to manage because of its length. Is there a way to move some of these methods to a separate file? If so, what are the mechanics of linking the together? Or is there another approach to manage long programs?

    JBD

    B B 2 Replies Last reply
    0
    • U User 13482557

      I have written a program the has numerous methods in form1.cs file and it has become somewhat difficult to manage because of its length. Is there a way to move some of these methods to a separate file? If so, what are the mechanics of linking the together? Or is there another approach to manage long programs?

      JBD

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

      To me a good sign of "good practice" would be that someone else reading your code would have some clear ideas about its structure, and what it does, just by looking at the use of namespaces, classes, method names. variable names. This is a very broad question, and it may well relate to bigger-picture issues in object-oriented design (OOD). Do you know about SOLID, a coherent set of ideas for OOD [^] ? In WinForms, you can declare a Class as 'partial to get around the restriction on having a single Class definition across multiple files [^]. Other ways commonly used to group Methods, where the Method has no dependencies, include writing Extension Methods in a static Class [^]. Of course, you can also group Methods into a library, compile that to a .dll, load that into your project, and reference the assembly in your Class' code ... as long as those methods have no innate dependency on your app's run-time objects, declarations, etc.

      «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

      J 1 Reply Last reply
      0
      • B BillWoodruff

        To me a good sign of "good practice" would be that someone else reading your code would have some clear ideas about its structure, and what it does, just by looking at the use of namespaces, classes, method names. variable names. This is a very broad question, and it may well relate to bigger-picture issues in object-oriented design (OOD). Do you know about SOLID, a coherent set of ideas for OOD [^] ? In WinForms, you can declare a Class as 'partial to get around the restriction on having a single Class definition across multiple files [^]. Other ways commonly used to group Methods, where the Method has no dependencies, include writing Extension Methods in a static Class [^]. Of course, you can also group Methods into a library, compile that to a .dll, load that into your project, and reference the assembly in your Class' code ... as long as those methods have no innate dependency on your app's run-time objects, declarations, etc.

        «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

        J Offline
        J Offline
        josda1000
        wrote on last edited by
        #3

        just a quick correction: It's not WinForms that defines partial classes, but the languages of C# and VB do. You don't need a WinForms project to make use of the feature.

        Josh Davis
        This is what plays in my head when I finish projects.

        B 1 Reply Last reply
        0
        • J josda1000

          just a quick correction: It's not WinForms that defines partial classes, but the languages of C# and VB do. You don't need a WinForms project to make use of the feature.

          Josh Davis
          This is what plays in my head when I finish projects.

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

          Thanks, Josh !

          «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

          1 Reply Last reply
          0
          • U User 13482557

            I have written a program the has numerous methods in form1.cs file and it has become somewhat difficult to manage because of its length. Is there a way to move some of these methods to a separate file? If so, what are the mechanics of linking the together? Or is there another approach to manage long programs?

            JBD

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            When someone starts programming, the first concepts he's learning are "procedural" concepts, i.e. how to control the program flow (if...else, for, do...while etc). Another concept is "object orientation". Now you have to think of "encapsulation of data" (how to access them, and more important how to change them safely), and eventually of components and their interactions. Bill mentioned SOLID: those are 5 ways for creating components and having them interact. "S" stands for "single responsibility" and is a good point to start with: a class takes care of one thing only, a function in that class of one action only. This change in paradigm from mere procedural code to object oriented code is a big step.

            Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

            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