And assuming that arg2 actually means something (and isn't a dummy value that's there just to force the two-arg version to be called).
–
cHaoDec 20 '12 at 3:47

The reason for the overloaded do(arg1, arg2) is because the do(arg1) creates a new object. When it does so, it automatically sets an argument to 'true'. With do(arg1, arg2), arg2 gets passed to the new object call.
–
Kevin MeredithDec 20 '12 at 3:49

But what if 'arg2' does not apply to every implementation of the interface?
–
Kevin MeredithDec 20 '12 at 3:59

2

@Kevin: Then you have DIP issues. You're making your code dependent on a particular concrete type. You might as well toss out the interface at that point, cause it doesn't mean anything. :P
–
cHaoDec 20 '12 at 4:07

2

If it can have variable number of parameters, use params instead in interface.
–
TilakDec 20 '12 at 4:15

I think you may not be fully understanding what the purpose is behind programming to Interfaces. The reason to do it is so that any client code can get an object of type IThing and know what to do with it. So there would be no way for the overloaded method to ever be called by a client whose entire knowledge of the ThingImpl is that it is an IThing.

That said, I frequently consider my Application as a system similar to ordering something from Amazon.com. I order something and an IThing is made in the Factory. The wiring code in the application is quite happy with an IThing, as the UPS truck is with a box. However, when the box get to its destination, I care again that what's in my box is exactly what I ordered (so I'll check the inventory to make sure the content of the box is specifically what I'm expecting). More literally, the endpoint code will check the implementation type of the IThing before attempting to use it.

It sounds like your code actually is the Factory. In cases like this, I'll actually just create two Factories, one that knows how to set the parameter to true, and the other which knows how to set it to false. The Factories will be stored in some sort of hash and called up based on the specifics of whatever I'm creating (for example, I might have a registry of Factories that create Question data objects based on information I get from an XML file, and I'll pull a particular Factory out of the hash based on the question type).

how do I reconcile the other two posters' comments as "it is a common pattern" with your post? Thanks
–
Kevin MeredithDec 20 '12 at 15:29

Not everything that is common is in accordance with what is good practice or in-depth understanding of the subject. For example, in the language I code in most, it's considered bad practice to use anonymous functions. However, I went in and dug a bit deeper myself and found that the truth is a bit more nuanced, and there are some occasions where an anonymous function will solve the problems we're all told they cause better than other types of function. So you need to make sure you have a full understanding of the principle and judge advice in that light.
–
Amy BlankenshipDec 23 '12 at 19:55