java - What is the recommended size of a class? -


a have been writting java ee 6 web application first serious application coding. have noted classes big 500 lines 1000 , bigger. have no idea how big class should or if matters @ don't want continue writting gigantic classes if going impact applications performance negatively. advice have me?

"the first rule of classes should small. second rule of classes should smaller that."

the name of class should describe responsibilities fulfills. in fact, naming first way of helping determine class size. if cannot derive concise name class, it’s large. more ambiguous class name, more has many responsibilities. example, class names including weasel words processor or manager or super hint @ unfortunate aggregation of responsibilities.

we should able write brief description of class in 25 words, without using words “if,” “and,” “or,” or “but.” how describe superdashboard? “the superdashboard provides access component last held focus, , allows track version , build numbers.” first “and” hint superdashboard has many responsibilities.

we want our systems composed of many small classes, not few large ones. each small class encapsulates single responsibility, has single reason change, , collaborates few others achieve desired system behaviors.

cohesion = classes should have small number of instance variables. each of methods of class should manipulate 1 or more of variables. in general more variables method manipulates more cohesive method class. class in each variable used each method maximally cohesive. in general neither advisable nor possible create such maximally cohesive classes; on other hand, cohesion high. when cohesion high, means methods , variables of class co-dependent , hang logical whole.

-from clean code: handbook of agile software craftsmanship


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -