Click here to Skip to main content
15,891,607 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: Feedback on my article? Pin
Richard MacCutchan11-Mar-14 6:28
mveRichard MacCutchan11-Mar-14 6:28 
QuestionOptimization algorithm Pin
Gordon Knot5-Mar-14 14:05
Gordon Knot5-Mar-14 14:05 
AnswerRe: Optimization algorithm Pin
Richard MacCutchan5-Mar-14 22:39
mveRichard MacCutchan5-Mar-14 22:39 
QuestionMathematical calculation of rating Pin
M i s t e r L i s t e r5-Mar-14 7:12
M i s t e r L i s t e r5-Mar-14 7:12 
QuestionRe: Mathematical calculation of rating Pin
Richard Deeming5-Mar-14 8:29
mveRichard Deeming5-Mar-14 8:29 
AnswerRe: Mathematical calculation of rating Pin
M i s t e r L i s t e r5-Mar-14 8:40
M i s t e r L i s t e r5-Mar-14 8:40 
GeneralRe: Mathematical calculation of rating Pin
Richard Deeming5-Mar-14 9:44
mveRichard Deeming5-Mar-14 9:44 
QuestionAm I using dependency injection, interfaces, unit testing, in the correct manner? Pin
AndyStephens4-Mar-14 2:03
AndyStephens4-Mar-14 2:03 
I've recently been having doubts about the way I've been approaching certain aspects of OO design in my projects (C#), and am looking for some advice. I use Castle Windsor IoC/DI framework, where dependencies are injected via class constructors. I also use a mocking framework (Moq) for my unit tests.

To support both frameworks I tend to find myself doing one of two things:

- creating an interface for every class, even if it's internal, or unlikely to have more than one concrete implementation (such as helper classes)
- or, I'll make such a class "mockable", which requires giving it a parameterless constructor, and marking its members as "virtual".

Both of these approaches feel like I'm writing additional code just to satisfy these two frameworks (particularly unit testing), but it does mean I can test a class in isolation, without it calling into potentially complex helper class functionality (which is the whole point of a unit test isn't it?).

My projects are typically self-contained desktop applications with no public API. Some articles I've read suggest that I should therefore not be using things like DI and interfaces, and I shouldn't even be unit testing internal classes. If I followed the latter advice then none of my code would be covered! (If you're wondering, I'm able to unit test internal classes because I use the "InternalsVisibleTo" attribute in my assemblies).

I'm now wondering if I'm taking the "separation of concerns" aspect of OO too far? Am I right to be using dependency injection with internal classes that will only ever have one concrete implementation (e.g. a "helper" class)? Or should I ditch DI and just instantiate such dependent classes? The latter would of course create a strong-coupling, making unit testing more difficult, especially if that helper class contained complex functionality, did database work, etc.

I hope I've made my concerns clear. To summarise, I guess I would like to know if I'm not using DI for its intended purpose, and whether my approach to unit testing and mocking is correct.
AnswerRe: Am I using dependency injection, interfaces, unit testing, in the correct manner? Pin
Jonathan Davies4-Mar-14 5:57
Jonathan Davies4-Mar-14 5:57 
QuestionCodeProject Infrastructure Pin
CodeHawkz18-Feb-14 12:34
CodeHawkz18-Feb-14 12:34 
AnswerRe: CodeProject Infrastructure Pin
Richard MacCutchan18-Feb-14 22:30
mveRichard MacCutchan18-Feb-14 22:30 
GeneralRe: CodeProject Infrastructure Pin
CodeHawkz19-Feb-14 6:47
CodeHawkz19-Feb-14 6:47 
AnswerRe: CodeProject Infrastructure Pin
thatraja18-Feb-14 23:56
professionalthatraja18-Feb-14 23:56 
GeneralRe: CodeProject Infrastructure Pin
CodeHawkz19-Feb-14 6:50
CodeHawkz19-Feb-14 6:50 
GeneralRe: CodeProject Infrastructure Pin
thatraja19-Feb-14 7:07
professionalthatraja19-Feb-14 7:07 
GeneralRe: CodeProject Infrastructure Pin
CodeHawkz19-Feb-14 7:42
CodeHawkz19-Feb-14 7:42 
QuestionMultiple methods vs Single method with enum Pin
Harley L. Pebley18-Feb-14 7:51
Harley L. Pebley18-Feb-14 7:51 
AnswerRe: Multiple methods vs Single method with enum Pin
jschell18-Feb-14 9:07
jschell18-Feb-14 9:07 
GeneralRe: Multiple methods vs Single method with enum Pin
Harley L. Pebley19-Feb-14 5:21
Harley L. Pebley19-Feb-14 5:21 
GeneralRe: Multiple methods vs Single method with enum Pin
jschell20-Feb-14 8:12
jschell20-Feb-14 8:12 
GeneralRe: Multiple methods vs Single method with enum Pin
Harley L. Pebley20-Feb-14 9:53
Harley L. Pebley20-Feb-14 9:53 
GeneralRe: Multiple methods vs Single method with enum Pin
jschell21-Feb-14 9:05
jschell21-Feb-14 9:05 
GeneralRe: Multiple methods vs Single method with enum Pin
Harley L. Pebley21-Feb-14 9:54
Harley L. Pebley21-Feb-14 9:54 
AnswerRe: Multiple methods vs Single method with enum Pin
Bernhard Hiller18-Feb-14 21:34
Bernhard Hiller18-Feb-14 21:34 
GeneralRe: Multiple methods vs Single method with enum Pin
Eddy Vluggen19-Feb-14 0:32
professionalEddy Vluggen19-Feb-14 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.