DEV Community

Discussion on: Do you (re)arrange your class methods? Why?

Collapse
 
bousquetn profile image
Nicolas Bousquet • Edited

I try to put methods working on the same subject near to each other. But I tend to put constructors/init methods at the begining of the file, just after fields and constant.

Sometime I like to have the public interface method first and their implementation later on.

But to me, if a class/file has more than a few methods with some significant code, it start to lack readability and I prefer to refactor.

200-300 lines for a file is great. 500 lines is acceptable. 1000+ is usually bad. That counting imports, comments and all.

There obviously exception. Facades for example shall have all the relevant method to help discoverability and keep things clean. But that doesn't mean the implementation has to do more than just redirecting to other classes that do the actual job.