Forums Register Login

How can they instanciate this Interface like this?

+Pie Number of slices to send: Send
Hi all,
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:



How is this possible?

Best
+Pie Number of slices to send: Send
I don't see "Session" -whatever that is- getting instantiated anywhere: it gets passed in via the onLoginSuccess method and then stored and used later on.
+Pie Number of slices to send: Send
Hi Tim,
but how can that be without implementing all the interface methods?

Kind Regards,
+Pie Number of slices to send: Send
I can't see Session is being initialized anywhere, its just being used as reference.
Isn't is possible that session is being referenced to some concrete class object which is not pasted in code.
+Pie Number of slices to send: Send
I don't understand the question. The class you posted does not claim to implement (or extend) "Session". It merely uses such an object that gets passed to it.
+Pie Number of slices to send: Send
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 !
1
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Thanks Steve, I think I get it now!
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 982 times.
Similar Threads
RMI over the Internet inc. Callbacks (Lipe RMI)
CRUD + Hibernate + GWT
Grid with Ext-GWT (GXT) and RPC - call
Help with Chat software
GWT fileuploading error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:56:19.