thelordoftherings
Programmer
Hello,
Let's say I have Interface IA and a class A which implements this Interface.
In many vendors code I see:
IA myA = new A() in addition many get methods return IA instead of A like this IA myA = myObject.getA()...
My question is this: What is the benefit from assigning the created Object into the Interface and not into the implemented class. Clearly the new A() ans well as the getA() creates an instance in memory, so why use this method? Is it just for convenience reasons or is there an efficiency consideration I am not aware of... ?
Roy
Let's say I have Interface IA and a class A which implements this Interface.
In many vendors code I see:
IA myA = new A() in addition many get methods return IA instead of A like this IA myA = myObject.getA()...
My question is this: What is the benefit from assigning the created Object into the Interface and not into the implemented class. Clearly the new A() ans well as the getA() creates an instance in memory, so why use this method? Is it just for convenience reasons or is there an efficiency consideration I am not aware of... ?
Roy