363 reputation
210
bio website
location United States
age
visits member for 3 years, 9 months
seen 2 days ago

Jan
31
comment How do I inject test objects when the real objects are created dynamically?
That's been my general approach, but in this case there are several subclasses of Validator, and there's a lot of setup involved in the test. If I make a test subclass, then I have to also make a test subclass for every real subclass of Validator. So I'll end up duplicating a lot of my setup work. But maybe that's necessary in this case.
Jan
31
comment How do I inject test objects when the real objects are created dynamically?
I left it out, but there are other methods that provide access to the ErrorList object. So I can test using those.
Jan
31
asked How do I inject test objects when the real objects are created dynamically?
Jan
31
revised Gradual approaches to dependency injection
added 291 characters in body
Jan
29
comment Gradual approaches to dependency injection
Thanks. I'm considering this approach for some cases. But what do you do when MyObject's constructor requires parameters that are only available from inside your class? Or when you need to create more than one MyObject during the lifetime of your class? Do you have to inject a MyObjectFactory?
Jan
29
revised Gradual approaches to dependency injection
added 274 characters in body
Jan
29
comment Gradual approaches to dependency injection
There are a lot of "new X" scattered throughout the code, as well as many uses of static classes and singletons. So when I try to test one class, I'm really testing a whole bunch of them. If I can isolate the dependencies and replace them with fake objects, I'll have more control over the testing.
Jan
29
asked Gradual approaches to dependency injection
Jan
26
revised Is a single config object a bad idea?
added 56 characters in body
Jan
26
comment Is a single config object a bad idea?
Well, no. But there are alternatives: combining multiple settings into objects, or using default values for some settings, with setter methods to override them. I agree that a single config object gives you a lot of convenience; that's why I've been using it all along. My purpose for asking this question was to think about whether it's worth the tradeoffs.
Jan
26
awarded  Nice Question
Jan
26
comment Is a single config object a bad idea?
@Anon: I guess the problem is that when I construct an object, I don't know which config settings all its dependencies use. If they were individual parameters, this would be more clear, and I could require them in the constructor. But since the config object is essentially a big hashmap, I can't see which settings are used by which classes.
Jan
26
comment Is a single config object a bad idea?
@AndrewKS: My config class is essentially a big pool of name-value pairs. Any class can use any of them. So when you construct an object X, it might construct an object Y that reads its own config settings. Right now, you can set up the config object with X's settings but not Y's. Obviously this is a problem, but it seems inevitable if everyone can read from the same config object.
Jan
26
awarded  Supporter
Jan
26
comment Is a single config object a bad idea?
True. But if I continue using a single pool of settings (with a different pool for testing), then all my tests end up using the same settings. And since I may want to test the behavior with different settings, this isn't ideal.
Jan
26
awarded  Editor
Jan
26
awarded  Student
Jan
26
revised Is a single config object a bad idea?
added 1 characters in body
Jan
26
comment Is a single config object a bad idea?
That solves the first problem, but not the second.
Jan
26
asked Is a single config object a bad idea?