Interfaces with Generics - HELP ?!
Posted: Sat Mar 25, 2017 2:53 pm
Hi Nick, Frank, all guys,
I am following your suggestions and now trying to integrate some suitable Generic Interfaces (of my own making) into my demo code for the 'Stock' sample for Cologne. So I am adapting an existing app.
At the moment I am unsure as to where to place / use the Interface, should it be in each of my business classes, like 'Customer' and 'Order', or in a Base class like 'DataAccess', which I use in some other way in the body of my code.
Let me show you what I have done so far, and you can then advise and criticise me.
Here is what I came up with when I considered my business classes, these methods could be applied to all my classes :-
First of all, I am unsure as to whether I have/need <T> in the method definition / declarations.
For the moment and some early testing I came up with this code seen below :-
And here is some test code to use the Interface :-
For now, I have simply sub-classed my main Order class to 'MyOrder' and implemented the Interface.
For the moment I am just returning dummy test data - with no processing code. And here are some runtime results :-
So guys, my questions are, do I need to have the 'T' in my methods ?
Am I best in implementing the interface in the business classes themselves - or another class altogether ?
Basically HELP !!! I feel close but it feels as if I am going about things wrongly.
Try to give me an answer which is understandable to a newbie to Generic Interfaces, so I can get it working and also explain in in my eNotes that I am writing.
Fingers crossed,
Cheers, and Best regards,
Phil.
Wales, UK.
I am following your suggestions and now trying to integrate some suitable Generic Interfaces (of my own making) into my demo code for the 'Stock' sample for Cologne. So I am adapting an existing app.
At the moment I am unsure as to where to place / use the Interface, should it be in each of my business classes, like 'Customer' and 'Order', or in a Base class like 'DataAccess', which I use in some other way in the body of my code.
Let me show you what I have done so far, and you can then advise and criticise me.
Here is what I came up with when I considered my business classes, these methods could be applied to all my classes :-
First of all, I am unsure as to whether I have/need <T> in the method definition / declarations.
For the moment and some early testing I came up with this code seen below :-
And here is some test code to use the Interface :-
For now, I have simply sub-classed my main Order class to 'MyOrder' and implemented the Interface.
For the moment I am just returning dummy test data - with no processing code. And here are some runtime results :-
So guys, my questions are, do I need to have the 'T' in my methods ?
Am I best in implementing the interface in the business classes themselves - or another class altogether ?
Basically HELP !!! I feel close but it feels as if I am going about things wrongly.
Try to give me an answer which is understandable to a newbie to Generic Interfaces, so I can get it working and also explain in in my eNotes that I am writing.
Fingers crossed,
Cheers, and Best regards,
Phil.
Wales, UK.