C# Method returning Interface vs Object

Question posted in Computer Software on 09 2009
Rate question difficulty level 0 Votes

What's the difference between these 2 methods?
is one of them is more better then the other?

1. MyObject DoSomething(string someInput)
2. IMyObject DoSomething(string someInput)

 
 
1 Answer
 

In term of using the methods , the usage is the same.
although the second approach is more flexable, enables the method's owner
to change the return value without changing the method signature and therefore
there's no need to comiple the code again.

returning an interface enables the method owner to change the return value from an object to a
list of object or even a primitive type without breaking the code.


09/29/2009
 
 
Add an answer*
 
Email
Location: Glil Yam , Israel
C# Method Return Value Interface
Now hiring!
Intuit 
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------