Let's say I have ThingImpl and IThing. The former is an implementation of the latter, which is an interface.
IThing has 1 method: do(arg1)
Is it considered a hack/bad practice to add a method in addition to do()?
Example: do(arg1, arg2)
|
Let's say I have IThing has 1 method: Is it considered a hack/bad practice to add a method in addition to do()? Example: |
|||
|
|
|
Assuming that |
|||||||
|
|
As Oleksi mentioned, it is a common pattern. But make sure it is not public. If you want to make it public, better add to Interface itself. |
|||||||||||||||
|
|
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 That said, I frequently consider my Application as a system similar to ordering something from Amazon.com. I order something and an 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). |
|||||
|