An Unbiased Description Of Interfaces
ProgrammingAn interface is:
- the list of operations understood by the object
- the arguments these operations can be supplied with
- the types of results the operations return
What #1 - #3 mean is that you as a developer can be handed an object that you have no idea how it works but because it adheres to an interface you know what it does. This also means that you can write an interface for something you need -say image resizing- and use that interface throughout your program. Then give your interface to some other programmer to develop and as long as they adhere to that interface it will work in your code.
- the invariants preserved despite modification to the object
An invariant is a condition that does not change. The simplest example I can think of is where you have an object with two fields (variables): VariableA and VariableB then in a method that receives an argument and sets the value of VariableA the value of VariableB should not be changed after the method returns. This is important because if you call a method you have to have a clear understanding not only of what was modified but what wasn't.
- any exceptional situations the client using the interface must handle
Error handling is important especially when code is being written by more than one person. Supplying the exceptional situations of a method is a good way to ensure that everyone is on the same page.



Loading....