Object Calisthenics Cheat Sheet by museumoftechno
Intended as a desktop resource to help work through the Object Calisthenics exercises
design code object oriented calisthenics sofrware
Wrap primitives and strings in objectsAn Hour object's type-hint in the parameters of a function tells you about the meaning of that parameter | You can add relevant methods to wrapper objects, cutting down on duplication - EG a round() function as part of a Money class |
Don't abbreviateIs a method name too long? Maybe it is doing too much | Are you having to type the method name a lot? Maybe you're missing an opportunity to de-duplicate? |
No more than two instance variables per classIf a class is dealing with lots of instance variables, it's probably doing too much | If a class has lots of dependencies, maybe moving responsibilities from one dependency to another might help eliminate dependencies |
| | One indentation level per methodPromotes method cohesiveness | Try to ensure each method does exactly one thing | Methods may well become better named as they become simpler and their responsibilities more focused |
First class collectionsEvery collection is wrapped in its own class | Methods (EG filters) proper to a collection can be added to the wrapper class | Processing that needs to be carried out on every member of a collection can go in the wrapper class |
Keep all entities smallEach method <= 5 lines | Each class <= 50 lines (~10 methods) | Each package <= 10 files | Methods, classes AND PACKAGES should be cohesive |
Don't use getters/setters | | Don't use ELSEFavour polymorphism over conditionals | Should make classes smaller, simpler, tighter | Also try Null Object pattern |
One dot per lineIf an object is juggling lots of other objects, it knows too much | If you're chaining together lots of calls to objects to return yet other objects (or grab them from object properties), then acting on those objects in turn... that's a code smell | Consider moving processing from current object into other objects | If you're digging deeply into another object and rearranging it, you're violating encapsulation | You can play with your toys, toys that you make, and toys that someone gives you. You don’t play with your toy’s toys |
|
Download the Object Calisthenics Cheat Sheet
1 Page
http://www.cheatography.com/museumoftechno/cheat-sheets/object-calisthenics/
//media.cheatography.com/storage/thumb/museumoftechno_object-calisthenics.750.jpg
PDF (recommended)
Alternative Downloads
Your Download Will Begin Automatically in 5 Seconds.
Close
Cheatographer
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets