Skip to content

Instantly share code, notes, and snippets.

@fredv
Created March 14, 2012 11:45
Show Gist options
  • Save fredv/2035960 to your computer and use it in GitHub Desktop.
Save fredv/2035960 to your computer and use it in GitHub Desktop.
Collected Ideas on OOP and Software Design as of now
Collected Ideas on OOP and Software Design as of now
Just One Idea (Jeff Casimir et. al.)
Application - ONE value proposition (monolithic is crappy)
Module - collection of ideas
Class - one domain
Method - one purpose
Line - one thought
Clarity over brevity: (Jeff Casimir et. al.)
- No more STI (Just rails)
- Module self.included pattern harmful because of side effects => Delegation, Injection instead => clarify responsibility
- Turn scopes into class methods
- Brevity is side effect of refactoring, not goal.
Coupling and Cohesion (Kent Beck et. al.)
- probability driven (what are the chances that i am going to change my database server architecture, YAGNI)
- Just one idea can be rule of thumb for separation or merging of code
- looser coupling eases testing
- higher cohesion should make things more understandable
Tell, Don't Ask (e.g. Alec Sharp, Smalltalk by Example, 1997)
- Don't ask objects about their state, make a decision and tell object what todo; rather move this code into the object, since it's probably the objects responsibility
- Public getters only to gather information about state of object, but not to base decisions upon
- Code smell or sign for lack of cohesion, too much coupling (between "asking" caller and "told" object)
- feature envy, since functionality probably rather belongs to object for higher cohesion and clear responsibility
- breaking law of demeter may be sign for this (a.k.a. reaching through to objects getters or even subobjects, "tree.apples.ripe.first.eat!")
Design patterns as Toolbox (Martin Fowler et. al.)
- most problems have already been solved by someone
- not just for the sake of the pattern, but as rule of thumb for better structure of the evolving code
- timeframes for refactoring
- early refactoring as practice of improving skills and to reduce technical debt, increase further flexibility, agility towards functional changes and adaptions
=> Make implementation fade away, closer to natural language / what you are doing.
=> Naturally readable code makes refactoring much easier. So first step: Try to explain by naming what the code is doing (or supposed to). Whenever this is hard or too general or implies ExtractMethod/ExtractClass one has a starting point for a refactoring.
@snuggs
Copy link

snuggs commented Mar 16, 2012

Don't forget "Tell! Don't ask!" from the smalltalk guys. it will change your life!

@fredv
Copy link
Author

fredv commented Mar 19, 2012

Thanks, stumbled upon this while refreshing my understanding of coupling and cohesion ( Article on Pragmatic: http://goo.gl/6m6Fg ) and added it as suggested to the list, pointing out why could be viewed as an implication or pattern evolving from thinking about just that: coupling and cohesion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment