The Student Room Group

why is interface useful?

i know what interface is

my senior usually adds an interface for the member and admin class so we must include a login function and a few others

What i dont understand is why is this even necessary? Why limit what programmers can do? I dont see any benefits of using interface.
I'm not too sure about other languages, but in C# especially you can define variables and parameters to be of type interface e.g
'IMyInterface myVariableName' which can then be assigned an object which implements that interface. It can be quite useful as you know for certain that an object passed in/assigned is guaranteed to have a certain method. The contents of the method may vary between different objects who may have implemented the interface differently and so may result in a varied outcome.
there would be no difference using interface and no interface

the only use i can think off is tech lead wants to remind dev not to miss out certain crucial methods, but that seems a bit excessive
Reply 3
The beauty of using the interface is you can write code that expects the interface 'type' and will work with whatever type of object it is passed, so long as it implements the correct interface.

Quick Reply

Latest

Trending

Trending