I\'ve been delving into more \"organized\" programming recently and I\'ve been l
ID: 644193 • Letter: I
Question
I've been delving into more "organized" programming recently and I've been learning that I should be programming to an interface, not an implementation. With that in mind, would it be better to "sketch" out a project in interfaces before writing the implementation for it where possible?
And if this is the case, in the case of using 3rd party libraries (ie Lidgren), should I be wrapping those in interfaces as well and resolve them through IOC containers, or is it OK to expose them to the interfaces?
Explanation / Answer
Unfortunately, you'll find this often boils down to personal preference.
What you've described so far, though, seems good. In fact, if you wanted to (and I recommend it) you could use the following approach:
Write your application skeleton as Interfaces, abstract classes (stubbed), and classes (also stubbed)
Write your tests against those interfaces and stubs (they will fail for now)
Write your implementations (your tests will start passing as you finish your implementation)
You're focusing on trying to write more "organized" code. Following TDD will help you with this.
Some extra points:
IoC containers are convenient. Use them and DI as much as you can.
Do wrap 3rd party libraries. This will loosen the coupling between your code (code you control) and 3rd party code (code you don't control)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.