Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"The purpose of class is to minimize complexity" "The purpose of class is to organize code" "A class should have one, and only one, reason to change"

What?

What about: "The purpose of class is to encapsulate state".

If there is no inner fields in class, there is no reason for class. There is no state.

One or more fields in class means that they make sense when looking at all of them together, as a "state". If some method changes something, the all state encapsulated by class means something else.

It is possible to extrapolate all other guidelines from this basic starting point.



Do you see "having a state" as "being able to change state" ? Because classes may be used to represent concepts or objects from the real world. Some of them may not have a changeable state but inner fields certainly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: