PDA

Click to See Complete Forum and Search --> : VB COM using Implements Keyword


Boredbert
Aug 15th, 2001, 10:02 AM
In a book we purchased on COM specifically tailored to VB (VB COM by Wrox Press)... the author insists on creating his interfaces using separate class modules then using the Implements keyword to assign them as the Interface in another Class module.

He gives the example of a IFarmYardAnimal class which is the Interface for CCow. So, CCow would contain code that looks like:

Implements IFarmYardAnimal

And then CCow would have a method like IFarmYardAnimal_Sing in which you would "Make the cow sing"

The implementation gets nasty when you must do this:

Dim o As New CCow
Dim i As New IFarmYardAnimal

Set i = o

i.Sing


I realize one might use this to keep versioning in check easily, but...

My question is: Has anyone ever seen this done with a professionally published component? Or in your own? Are there alternatives to changing or adding Interfaces to components?

jim mcnamara
Aug 15th, 2001, 03:17 PM
The reason for Implements is to help to avoid breaking binary compatibility.

You don't know it yet, but when you create an ActiveX DLL in VB, VB may have it implement 20 -25 interfaces, most all of them standard ones like IMoniker, or IUknown. All behind your back.

Once you code this stuff in C++, you will begin to understand what interfaces are there. Because you have to explicitly define them and know when to include them. And why.

And yes, multiple interfaces is standard in the real world. IFarmyardAnimals definitely isn't.

Download OLEVIEW from MSDN. It allows you to look at compiled idl files (.TLB's - type libraries). Software like Word from Microsoft will implement a large number of interfaces.

That book is written for VB programmers, most of whom have produced code for years and still know next-to-nothing about COM. I've used the Thomas book in teaching COM, and I think it's just right for most VB'ers. But. 'VB COM' is very short on some MTS and DCOM stuff, for example, in-process DLL's often make truly awful DCOM servers.

'VB COM' is obviously is not right for you. Jose Mojica & Ash Rofail both have several really well-received titles out - give one of them a spin.

SoftwareMaker
Aug 15th, 2001, 08:52 PM
Jim is right...Overt the years MS has protected VB Programmers from the innards (YUCKS....) of COM because VB started out to appeal to the masses of NON Comp-Science(CS) people. The reason it took off to be so popular is due to the support of people in the finance, engineering..etc industry. People who wanted to merge industrial domain expertise with just a working-know-how of a Programming language. VB was the one as it protected the end-user from the complexities and it was very FAST and PRODUCTIVE. I am not here to say whos Right or whos Wrong just to highlight the difference b/w 2 different groups of people.

CS People are very much into the design and the beauty of designing programming systems. To then, it is not just a science, it is an ART.

Non CS People, on the other hand, are more result-oriented and they want to have solutions FAST on the table. They are not much into how systems evolve or how they work, just getting the solution done in the shortest possible amout of time. Hey, after all, they are running a business, not an Art-show. The drawback is that systems created by the latter tends to be a nightmare to maintain and break over time as systems evolve.

A Good system should be 80% Design and planning and 20% Coding. BUT the latter group, will start coding right away so that they can have the project on time...and they will leave the awful maintenability, scalability and extensibility jobs to the CS people...who then grew up to hate and despise VB...:) :) :)

Fret NOT, VB developers will soon have to learn the workings of COM and all the innards of MS Technologies with the advent of VB.Net where the CLR will mean that all MS languages all work under a Common Runtime and MS chose VB to break...Good Choice...VB.Net will be a whole new language without the funny quirks and inefficiencies of VB that were built over time. The on Error goto 0 particularly erks me....:)

In VB.Net, you get to see all muck and goo of forms and classes.
VB programmers will realise how much they are shielded from MS over the years once they are exposed to the just the code behind a form :)

So, I guess all I have to say is that there wont be Implements keyword soon, which I agree is ugly, BUT its gets the Job done. It will be truly Inherit, Overloading and subclassing just the way it should be. VB.Net, will and can be considered to build enterprise-level apps because it can be easily maintained, scalable and extensible and will stand, more or less, shoulder-to-shoulder with its bigger cousins of C++ and Java...altho VB.Net cant do unmanaged code yet. :(

NOW the only thing is whether the other OS platforms comes up with their own JIT to support the running of VS Programs on their platforms.

Over in MS, its the power CS programmers that won over the VB camp even tho there were fewer of them (See Quote Below). VB.NET, i think, will be favoured by CS people more than the VB people now. I have no idea how, VB developers now (including me) are gonna make the transition to VB.net...I hope we can...for the good and future of VB.

My goodness...see what nonsense I have rambled in a thread name VB COM....Sorry about that...

"The people who vote decide nothing...The people who counts those votes decide everything" - Joseph Stalin