Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any VFP's FormCount equivalent in VB?
Message
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00414092
Message ID:
00417339
Vues:
22
>>>>>>>>>>>>>>>>>>>>>>>>
I have some questions:
1. How does Implements reduce copy and paste?
2. Multi-Casting is such a powerful feature (close inheritance simulation), why do I not see much use of it?
3. What is Composition?
>>>>>>>>>>>>>>>>>>>>>>>>

Hey George.
1) Actually, Implements allows you to inherit interfaces, not code, so it doesn't reduce cut and paste. I grouped it in with several other techniques that do, because it belongs in the same general family, but unless you are using delegation techniques, etc., it won't reduce much of anything.
2) I have no idea! I use it frequently these days, albeit for simple form validations, etc. It is, basically, a one-level inheritance (with an implicit and unavoidable DoDefault()). I really don't know why people are not using it more, and I certainly don't know why Microsoft doesn't really advertise it much (no knowledge base articles, that I could find). Francesco Balena and Ken Getz have each written great articles/chapters on these techniques.
3) Composition is an OOP principle, not specific to VB. In some respects, it is considered the opposite of inheritance -- basically, how do you re-use code? Well, let's say you have a special "DarnIt" method that needs to be called from every form. You can create this method up on the super-class level of the forms, and, voila! it's available. Or, you can create a class called Curses and have a DarnIt method in that class. Then, on every form that you need to use it, you can create this object and call the method. It's an extra line of code for every use (unless you put the code in the class's Init, in which case it's the same amount of code). This way, if, later on, you have a whole other set of forms that need the same method, but do not inherit from any classes in common with your first set of forms, you can still make use of this method.

But, personally, I disagree that it's the opposite of inheritance -- I use inheritance and composition together in VFP -- in the example above, I would probably have a super-class method called DarnIt that creates the Curses object and calls the DarnIt method.... then, forms down below have what they need, and if you want to call it from an entirely different spot (for instance, program code where the form is not accessible) you can create the object and call the DarnIt method. In VB I just create and call as needed.

Hope that makes sense.

I find myself very worried about what VB code will begin to look like for the first year after Inheritance is implemented. In the mid-nineties, we saw an awful lot of bad code and framework design in VFP due largely to inheritance-happy coders, and I fear we will see the same once this new toy is unleashed on the VB side of things. Everything has its place, of course, but.....
The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts. - Bertrand Russell
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform