Casting as Interface? Awesome.
- by cam
I was just experimenting around with one of my programs, trying to make it looks prettier and I found something interesting. I have an interface that 4 classes inherit from.
I found that if I pass the Class as an object to a method like so:
ClassTest classtest = new ClassTest();
DoOperation(classtest);
private void DoOperation(object o)
{
((InterfaceClass)o).DoThis();
}
So I can pass any type of class that inherits from InterfaceClass, and it will preform the proper interface operation? This is the coolest thing I've ever found from OOP (something I've never really studied)
I really thought interfaces were created for the sole purpose of organization for developers. Are there more uses for interfaces than this?