The difference is that in the second, using the interface, you can access only those members who are present on this particular interface, and not in the entire class. This allows you to implement several different interfaces for your actual class, while only a specific “skinder” is available to the user.
In addition, an interface-oriented design is good at unit testing, as you can simply share one class with another.
, , . , , , , , . , - TestClass AnotherTestClass -instances, , . , , , . , .
. , TestClass ITest, ITest TestClass. , InvalidCastException:
ITest t = new TesClass();
AnotherTestClass t2 = (AnotherTestClass) t;
, , , , , . : Program , TotalMarks , , , . Program. , losly class-binding.