Reputation: 11
I get confused when I read 'you are hiding concrete classes by using an interface'. Since when the app is used by another guy, he can see the entire code (unless I expose web services only...that is a different aspect, not to mix here)?
I agree that interfaces and abstract classes help to nicely design code, but from what I understand , that's it. I can't understand how practically in real world we are hiding stuff from others or adding more security etc.
Upvotes: 1
Views: 323
Reputation: 51034
You have a misconception that the reason for "hiding" something is security. That is not at all what "hiding" means in this context. An interface "hides" the implementation details of a class in the same way a car's engine is "hidden" under the hood. Of course this doesn't stop you from looking at the engine if you want to see the car's internal workings, but the important points are that
Likewise, by hiding the internal workings of a class, users of the class only need to understand how the class is meant to be used (i.e. its interface), and the developers of the class are free to change internal details of the class without annoying the users or breaking their code.
Upvotes: 6