+ 1

Really why we use interfaces ?? I can define methods freely without any inheritance.

please explain a necessary example, i am an unity3d programmer, i don't know what is interface advantage when i just can define methods separately on different components, it improves performance or something other in other code application like VS?

4th Sep 2019, 10:31 PM
KiynL
KiynL - avatar
6 ответов
+ 5
well i use java not c# but in java for example when you make an array of an class you can only put instances of that class and sub-classes into the array. with interfaces you can sort-of do multiple inheritance😅
4th Sep 2019, 10:57 PM
Anton Böhler
Anton Böhler - avatar
+ 4
probably for polymorphism...
4th Sep 2019, 10:37 PM
Anton Böhler
Anton Böhler - avatar
+ 4
Without inheritance and interfaces there would be unnecessary duplication of code.
5th Sep 2019, 3:11 AM
Sonic
Sonic - avatar
+ 1
its important to polymorphism ? i use unity game engine c#.
4th Sep 2019, 10:51 PM
KiynL
KiynL - avatar
0
In Object-Oriented Programming, an Interface is a description of all functions that an object must have in order to be an "X". Again, as an example, anything that "ACTS LIKE" a light, should have a turn_on() method and a turn_off() method.
22nd Jun 2022, 8:47 PM
Sufian Ahmad
Sufian Ahmad - avatar
0
KiynL OOP is all about making things easy. I use the interface as it makes it clear that every class will have a similar and unique implementation for similar behavior. Also Read about upcasting and downcasting :)
22nd Jun 2022, 9:00 PM
Sufian Ahmad
Sufian Ahmad - avatar