I am working with a java API from Lmax used for trading. I am getting things to work but a use of an interface bothers me.
The interface is called Session with many methods however it gets instanciated like this and not implemented as an Interface:
Carl Axwl wrote:I have to think about this a little , I am confused. Yes, it is just a reference but the Session class has no implementation anywhere just an Interface.
Thanks anyway !
Session has no public implementation anywhere. The code you call is designed to be registered with some other framework which calls onLoginSuccess() when appropriate. That external framework is charged with providing a session object. The framework must have some specific implementation of Session somewhere, but the implementation and specifics aren't important to this code. The only thing this code needs to know is the session implements the Session interface and therefore provides the functionality required by this code.
That is the beauty of interfaces. This code says 'give me an Object that behaves like the Session interface says it should' and the caller can provide any Object which implements the interface. It could be one that works with Databases to store data, or XML files, or memory, or synchronizes with multiple systems, etc... But this code doesn't need to know that. And if there is no obvious Session implementation in whatever framework you are working in, then it indicates the framework writers think you don't need to know the implementation details either - the implementation might be protected, private, or internal to some other class.