User:Average/Encapsulate

From HackerspaceWiki
Jump to: navigation, search

Synthesize and Encapsulate: If and when the conceptual units you are working with are too convoluted, find a better abstraction, something that is more generalizable which will hold it all (ZeroSuperfluousNames). Make a new module or a new object, gathering the diaspora. Synthesize to make SeparationOfDomains: generalizable, re-usable, loosely-coupled, modular code. Pull back and see the forest through the trees. Some code editors make this easy.

Function parameter lists should never be more than four variables long (if you're doing very specialized work, like writing a compiler, you might need five), otherwise you're almost certainly designing things wrong -- split your function into smaller, more generic functions that could have use later and are more understandable.

Same goes for classes/objects. If your API is more than four methods large (again: five for specialized classes like a container object), you should probably make a mashup of smaller objects. Use the power of inheritance wisely to keep your classes managable.

See also the Gospel of Object Oriented Programming. When you master the Tao, you'll see that you should have used message-passing all along and settled on ">>" & "<<" operators.

Continue to Divide and Conquer until you have a complete program. Then, and only then, do you pull out the last tool: Optimize.