Hello,
Class could have static, private, protected, public methods. Each method is made for modifying, adding, removing etc.
How do you group functions in class's code to make it clean to read? What is the best practices?
Thank you.
Hello,
Class could have static, private, protected, public methods. Each method is made for modifying, adding, removing etc.
How do you group functions in class's code to make it clean to read? What is the best practices?
Thank you.
This is how I do it for Java classes:
One convention need not fit all scenarios - typically, in our team, we use C# and we use "region" for grouping private fields, static members, private methods, constructors, protected methods and public methods. Order doesn't matter much because VS can collapse all regions nicely giving a summary view. Sometimes, we also use "overrides" and/or "virtual" regions. It also depends upon the complexity of the class in question. For few complex classes, you will even find regions based on functionality. For example, all "Parsing" stuff (variables, private methods, public methods involved in parsing) would be together under one region. In the end, goal is to have readable (maintainable) code and "consistency" would be one of the tool for that - as long as team understands this, there shouldn't be any issues.
If you have the need to organize the order of methods in your class, I'd say you're doing something wrong.