Google Search

Google
 

Wednesday, July 23, 2008

Video: VB9 - Dynamic Interfaces

Presenter:Mike Taulty

Dynamic interfaces bring the idea of 'duck typing' into Visual Basic 9.0, allowing you to reference an object through an interface even if the object does not implement the interface as long as the object matches the right 'shape'.

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video


Minute 0

Consists on then the recession hit one in a series of short videos will be spent 10 minutes or so looking at we can do things of visual studio and the net framework minus like Tolkien I work in the developer and platform group in Microsoft and UK and this is one of a number of videos about the changes coming in the future version of the Visual Basic language that Visual Basic nine and the amount you can download a preview version of that if you are looking for the language integrated query features all the features that here in the benign in the centre circle as whole feature called dynamic interfaces that Lessig isn t clever things with loose tightening in VB 9 okay so it officials and five I ve got him a preview of VB 9 installed and this idea of dynamic interfaces is one of trying to do something with a strongly tight line

Minute 1

That we would usually do so what I mean by that will act with a couple of glasses that have class shape and let our flasks cowboy and those of these types you have a method on called draw so other public saw them draw and public salt draw and that it is a devaluation could parameter on here and could branch on here and what would it ll create a method on module down here will have them private function create draw a figure of Williams and will return an object from here on what it will do oh as

Minute 2

Arafat would you say if he then will return a new shape else will return a new catwalk so as a programmer here we know that whatever object comes back from the single created role will have a method on a cold drawl takes a strength because both of classes do but they re not related by any kind of interface implementation severity go ahead as a general rule has object equals create draw and we can say that that s a true there might look to do then is go ahead and called for a man with some strength but the police become a forgotten and compile the cards league option stick switched on when I will add to delay binding

Minute 3

If it went ahead and switched off options straight men in VB this will work fine and approved as an code into these methods such as go ahead and say console all right line hello from the shape would have had a string that we get past similarly down he will say hello from cowboy and for that string out as well then that will work for us and a cigarette control a five year wicket hello from shape but we ve had to resort to switching off options straight and we ve lost our intelligence as to what we can do here are using reflection obviously to invoke this method and exactly this situation feeding nine hands what it calls the idea of a dynamic interface where he know that the objects that you re dealing with do have some constant pattern and you want to make use of that knowledge is awakened if you can go ahead and switch back

Minute 4

On options straight out of to declare ourselves a dynamic interface as well and I draw and I was allowed a court public sold draw S a string unfounded only the public managers have some draw case what I can do how exactly declare myself because I says as and I draw and I can say that my faces as change the type of boat do I draw I can go ahead in core methods nothing amazing and have a sense notice that neither shaken cowboy actually implement this interface but we are pretending they do with treating them dynamically is that they do now in this particular version that preview version of the compiler I know if I go ahead and completely fanatical here and getting a crash from the compiler at this point so I did my work around that doesn t see a preview problem and you change this and

Minute 5

Of draw here to not take parameter and a change cowboy so he didn t take the prize are either amateurs get rid of that ran to their and going to change shapes that he doesn t take parameter either is nothing wrong with using browsers it is as in several blog somewhere in the intelligence that breaks if I don t do this sort of the digital ankle effects draw and I should get me remind tellers and blog have got an exclusive therapist of dozen works will get rid of her organiser and has been given a quick run and we can see I have often shake their positive skipper on screen dignity that we are in fact invoking that method now you re probably wondering what happens if might draw we for a new soul but safely now neither of cowboy nor shaped that she has a clear methadone so what happens at this point where I set if you re heading all clear here noticed that the getting a callous sense again was a runtimes that might worry that method were going to get next

Minute 6

Should only did he essentially there wasn t a method coal clear on the shape so there s exactly going to come to you at the point here where you actually do the implication it doesn t combat you at this point he weeded the change type becomes that you describe only as she dynamically went off to invoke that method solicitor in Isa allows you to essentially go ahead and treat types and using a pattern if you like an interface that I ve is that they don t add him to implement the ecology know that certain types have certain shape in our case we know that both the sites have a so called draw on takes no parameters you can gone treat them as though he did and programming us in that way and they benefit of course as you get you into as intelligent back rather than floundering around in the dark trying to work with late binding where you don t get any kind of Intel sense it also lets you do a form of late binding year or two silver option strict on such colonisers were in itself is

Minute 7

Run that one must I just zero senior and dynamic interfaces are a feature of the VB 9 language he allows to define an interface am in the terms of the shapes of methods that we expect to see on a particular runtime type we can then point that interface at a particular instance of the type and start invoking as methods we can do it when we ve got a street switched on and we get falling telephones for the methods of Colin now if you don t take one of these dynamic interfaces and pointed out an object you won t get any errors at that point if the object doesn t actually match the dynamic interface what you get is errors at the point where you call the methods that don t match or don t exist on that type is important to realise that aren t you an idiot that there is when you actually gone call methods by other than that it s a great little feature for releases on nice work with this type

Minute 8

While still getting the benefits some of the benefits of traditional type safe compilation like and colour sense and so on where do you go to a more information on the VB 9 and language integrated query over the site anonymously only continuing there on the screen and site you ll find a document that talks about the changes in the VB 9 language that are forthcoming about the cities are not finished yet things could change and if you think back on this particular session feel free to mail me and his mike halting of Microsoft com the luckless listening thanks watching the session

Click here to go to original video page

No comments: