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. Design and Architecture
  4. Parameters

Parameters

Scheduled Pinned Locked Moved Design and Architecture
csharpquestiondiscussion
2 Posts 2 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 Offline
    C Offline
    CodingYoshi
    wrote on last edited by
    #1

    If one or more private methods of a class need a variable to perform some operation on, should one methods pass it to the other as parameters or should we make the parameter a private member of the class so both methods can access it? If we make it a class level variable then it will exist for the lifetime of the object. If we do not need it for the lifetime of the object, we are wasting resources. If we do not make it a class level variable then we have to pass it around to methods which need it. I am not sure what the disadvantage is here. If the class has 7 methods and 5 of them need the variable then we will pass it around to all these methods. If class level, then we will not need to pass it but it will exist for the lifetime of the object. Should it depend on how many different methods need the variable or should it depend on whether we need its existence for the lifetime of the object? What are your opinions? Any conventions?

    CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07

    L 1 Reply Last reply
    0
    • C CodingYoshi

      If one or more private methods of a class need a variable to perform some operation on, should one methods pass it to the other as parameters or should we make the parameter a private member of the class so both methods can access it? If we make it a class level variable then it will exist for the lifetime of the object. If we do not need it for the lifetime of the object, we are wasting resources. If we do not make it a class level variable then we have to pass it around to methods which need it. I am not sure what the disadvantage is here. If the class has 7 methods and 5 of them need the variable then we will pass it around to all these methods. If class level, then we will not need to pass it but it will exist for the lifetime of the object. Should it depend on how many different methods need the variable or should it depend on whether we need its existence for the lifetime of the object? What are your opinions? Any conventions?

      CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, it depends on the circumstances. If the parameters are like characteristics of the objects, then data members would be alright. If they are small, then having storage allocated for them for the lifetime of the object probably is irrelevant. If they more act like operational parameters, seems to me method parameters are in order; if they are many, you may want to create a separate struct or class to hold them and pass them around easily (kind of "job ticket"). :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      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