Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any VFP's FormCount equivalent in VB?
Message
 
To
21/09/2000 05:38:21
Marlou Gargantos
Independent Consultant
Manila, Philippines
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00414092
Message ID:
00419032
Views:
25
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I don't have problems with re-using Functions that gives or produces the same output in VB. What's lacking so far is subclassing a form or object in order to avoid cutting and pasting. Just imagine if you have 100 forms that uses similar properties and methods without inheritance. How do you accomplish this in VB?

100 forms which have the same properties and methods:

Private Var1 As String
Private Var2 As Boolean
Private Var3 As Integer

Public Delete_Record()
End Sub

Public Add_Record()
End Sub
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

There are many approaches. Please note that none of these will provide the same degree of reusability as inheritance does... I've never argued that point. But, there certainly are approaches that get you an awful lot of reusability even without inheritance (true of VFP as well as VB). And that's the point, I think -- how handicapped are VB programmers by not having inheritance? Certainly, somewhat.... but an awful lot of posts on the UT seem to indicate that it's much worse than is really the case. I'm worried that novices in VB are getting the wrong ideas.

For instance, you could have a class called clsDataBehavior, with methods called DeleteRecord, AddRecord, etc. Create the class in the form_load (or even in your app startup) and then fill in one line on each sub:
Public Delete_Record()
oDataBehavior.DeleteRecord(Me)
End Sub

Public Add_Record()
oDataBehavior.AddRecord(Me)
End Sub

Okay, I know what you are thinking -- yes, you have to add one line per method.... for 100 forms, that's a lot of lines.... in reality, that might take you up to ten minutes of cutting and pasting. That doesn't sound so bad to me.

In fact, there are even better approaches, but I wanted to take a basic example of delegation/composition and show how, without getting too fancy, you can re-use code.... as much as inheritance? NO. But how much does that ten minutes for 100 screens really hinder you?

And you are right, I do agree with JVP's comments on inheritance. I think inheritance is a frequently abused OOP feature. Over-reliance on inheritance causes larger EXEs, slower loading forms, slower debugging.... and in many apps I have worked on these costs are simply not outweighed by the benefits. Please note that I said "over-reliance" not "any-reliance."

Pete Townsend once said, about Rock and Roll, that you can go ahead and use more than three chords, but you'd better have a REALLY good reason. That's how I feel about inheritance. You can go ahead and inherit more than one level, but you'd better have a really good reason. (You often do! More often, you do not.)
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
Previous
Reply
Map
View

Click here to load this message in the networking platform