c++ - Good Practice: To Modify Only Function Parameters? -
say, develop complex application: within object member functions, should modify objects, passed member functions parameters, or can access , modify other objects have access to(say public or static objects)?
technically, know possible modify have access to. asking good practices.
sometimes, bothering pass argument everythying access , modify, if know object member function not used else, me. thanks.
global state never idea (though simpler, example logging), because introduces dependencies not documented in interface , increase coupling between components. therefore, modifying global state (static
variables example) should avoided @ costs. note: global constants okay
in c++, have const
keyword, document (and have compiler enforce) can modified , cannot.
a const
method guarantee visible state of object untouched, argument passed const
reference, or value, not touched either.
as long documented, fine... , should strive having few non-const
methods in class interface , few non-const
parameters in methods.
Comments
Post a Comment