When developping a project I follow the OOP principles and break my code into classes and most of the time I go for one file = one class.
Now I dont know how to organize my code into the class and even into my own functions/methods I'm still looking for ways to improve the readability.
I think the general consensus is :
- attributes
- Constructors
- Getters/Setters
- Methods
But once I get to the method part I dont know if I should organize by public/protected/private members, or if I should put related methods together ?
IE :
Methods for database operation, then methods for user input validation, then methods for event handling.
What If I put some code in a method, and then I call this method in a lots of my others class method ?
public void f1(){
mymethod();
// other stuff
}
public void f2(){
mymethod();
// other stuff
}
Where do I put 'mymethod' definition for an optimal readibility ? Should I declare it before f1 and f2 or after both ?