Podcast: Play in new window | Download
Subscribe: Apple Podcasts | Spotify | TuneIn | RSS
This week we tackle the SOLID principles in .NET and discuss the eternal struggle between perfect code and looming deadlines.
Please leave us feedback in your Podcasting app of choice!
Update: Great comments/debate on reddit!
About Solid
- SOLID Principles for writing maintainable and extendable software
- Michael Feathers and “Uncle Bob” Robert Martin
- May be impossible to follow 100%, but there are great lessons
- Balancing the SOLID principles with other principles
- YAGNI – You Ain’t Gonna Need It
- The Rule of 3
- DRY – Don’t Repeat Yourself
S – Single Responsibility Principle
- “Objects should only have one reason to change”
- Programmers are (maybe) masochists
- Class Explosion
- The perfect class is an interface 🙂
- Singletons are…controversial
- Dependency Injection can allow singletons without violating SRP
- Conditionals are a warning that your code might be violating SRP
O – Open Closed Principle
- “Objects should be open to extension, and closed to modification”
- Discourages changing code – Extend rather than modify to add/change functionality
- Arguing about whether “modification” refers to source code or overriding…Source code wins
- Template Method Pattern
- Strategy Pattern
- Decorator Pattern
- Hollywood Principle
L – Liskov Substitution Principle
- “Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.”
- IS-A deprecated, replaced with IS-SUBSTITUTABLE-FOR
- “is” is a code smell – polymorphism might provide a better solution. Say it like Jeff Foxworthy
- Square is a Rectangle Problem
- SOLID Principles of Object Oriented Design from @adaris
I – Interface Segregation Principle
- “no client should be forced to depend on methods it does not use”
- I is for Interface – Episode 1
- What are interfaces?
- Interfaces are really a big part of ALL the solid rules
- If you implement an interface, and throw new “NotImplementedException” errors, your code smells!
D – Dependency Inversion Principle
- “Depend upon Abstractions. Do not depend upon concretions.”
- The “new” keyword suddenly a smell
- Constructor, Parameter, Manual Injection
- Ninject
- Dependency Inversion in MVC…at the application level
Additional Resources
- Clean Code: A Handbook of Agile Software Craftsmanship
- Design Patterns: Elements of Reusable Object-Oriented Software
- SOLID Principles of Object Oriented Design on Pluralsight, from Steve Smith
- From STUPID to SOLID
- Object Calisthenics – 9 rules for stretching your skills
- Object Mentor Blog
Tips / Tricks
- Visual Studio 2013 – 64 bit code editing while debugging
- CTRL Shift S – Save All in VS…including sln/csproj files!
- Linq2Twitter