VB 4, Classes and OO stuff (LONG) 
Author Message
 VB 4, Classes and OO stuff (LONG)

*** VB4, Classes and Stuff ***
Target audience: VB experts, intermediate developers

I am nearly finished with my first 'real' VB4 project using classes, here
are some thoughts.  I dont purport to be the definitive expert on VB
classes or OO, but maybe you will find this of interest, if you havent
explored Classes:

* Project *
The project is not the biggest thing I have ever worked on but, it is
large enough to test some of the new stuff on VB4.  Essentially it is an
insurance program to calculate the rate for boats and yachts.  There are
lots of business rules involved (over 26 ft OR over $50k is a yacht; no
coverage for over 400 HP etc).

Target platform: VB4/16 for Win31/W95

* Classes and Objects *
If you haven't toyed with these, I urge you to do so now.  They are Mondo
Cool.  They more or less replace UDTs, dynasets and arrays.  At the same
time, don't be scared of them: they are little more than smart UDT's with
procedures embedded in them.

For instance, when I set the .VLen property of the CVsl (Vessel) object,
it evaluates it and if over 26 ft, sets the class code to "Y", othewise
"B" (the boat-yacht thing).

This allows you to encapsulate ALL the BRs, DVs and DT (Biz rules, data
validation and data transformations) in one place: the class module.  For
instance, the CVsl.IsValid property, when polled (PropertyGet), goes thru
all the class members (properties) and tests the required ones for in
range values. In so doing, it stores a string with all the errors ("HP,
Beam, Weight are required items"), that can be fetched later for display
to the user.

One thing the app has to do is perform a speed check.  Given the weight,
waterline, HP etc of the vessel what does this formula say the Max speed
is?  When the CVsl.MaxSpeed property is polled (PeopertyGet, again) the
formula is calculated and the Max speed returned.  

There are 2 cool things here: .MaxSpeed is ReadOnly - there is no
PropertyLet, since the class creates the data.  2) The speed formula is
not even in the Vessel class - it is in a Speed Class, since it is used
elsewhere.  Very cool and allows for MAXIMUM reusability of code.

Is it OO?  Well the above describes Data hiding, abstraction and
polymorphism.  3 out of 4 aint bad.  It misses on inheritance, but you can
get the benefits of inheritance by reversing it: rather than child objects
inheriting from the parent, just make the child a part of the parent.

But really, who cares?  Depending on how pure you want to get in your
definition most anything can be disqualified.  Delphi users poo-poo VB,
C++ users dump on delphi (it only supports single inheritance) and even
the Smalltalk people can make an argument that C++ is not "truly" OO.

I no longer care, and it does not matter in the long run: if it is
maintainable, encapsulated and polymorphic (the speed class never knows
when it is invoked from code or from the Vessel class; the IsValid method
works diffrently on the Vessel, Quote and Engine classes...), arent there
some benefits to be gained?  Yea, my Vb4 car only goes 75 mph, and that
Delphi one goes 85, BUT my old VB3 car only went 60, so I am better off.

*  VB Class Tips and Traps *
Beware your data types.  When you create a new Property from the menu, the
type defaults to Variant.  Take you time and re type them.  Eg:

Public PropertyLet VLen(vNewValue)

End Property

Public PropertyGet VLen()

End Property

when you add in the code, reset the property data type:
Public PropertyLet VLen(n as Integer)
    miLen = n
End Property

Public PropertyGet VLen() As Integer
    VLen = miLen
End Property

1) If you fix PropGet and forget PropLet it wont run, but it will point to
one of the Prop procs and tell you the data types do not match.  this is
good.  But SOME SLIP BY and the code runs...UNTIL YOU MAKE EXE, then the
damn thing just says one of the property types are mismatched and does not
tell you which one!!!!!!  Major PITA!  take your time!!!.

I have used all dialects of MS/IBM basic since BASCOM



Sun, 19 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)

says:
Quote:

[snip]
>1) If you fix PropGet and forget PropLet it wont run, but it will point to
>one of the Prop procs and tell you the data types do not match.  this is
>good.  But SOME SLIP BY and the code runs...UNTIL YOU MAKE EXE, then the
>damn thing just says one of the property types are mismatched and does not
>tell you which one!!!!!!  Major PITA!  take your time!!!.

[snip]

I'd imagine if you turned 'compile on demand' off that this problem will not
occur.



Mon, 20 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)

writes:

Quote:

>[snip]
>>1) If you fix PropGet and forget PropLet it wont run, but it will point
to
>>one of the Prop procs and tell you the data types do not match.  this is
>>good.  But SOME SLIP BY and the code runs...UNTIL YOU MAKE EXE, then the
>>damn thing just says one of the property types are mismatched and does
not
>>tell you which one!!!!!!  Major PITA!  take your time!!!.
>[snip]

>I'd imagine if you turned 'compile on demand' off that this problem will
not
>occur.

Nope, it is in the Make EXE.  The Start With Complete Compile does NOT
find it and the Make EXE does but DOES NOT highlight the line in error
(they obviously depend on the incremental comiles to have caught it).

- Mike



Tue, 21 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)

Quote:

>I no longer care, and it does not matter in the long run: if it is
>maintainable, encapsulated and polymorphic (the speed class never knows
>when it is invoked from code or from the Vessel class; the IsValid method

Not to be picky, but I think you've got this little bit backwards.
Polymorphism refers to the ability of the calling code to execute a
method on an object of an unknown type, and have the "correct"
implementation of the method resolved by the compiler/interpreter.
"Traditional" OOP languages use virtual methods and inheritance to do
this, while you can accomplish it in VB by using late-bound objects
(i.e. OLE objects created by CreateObject).

IMO VB4's new class features are a marked improvement over VB3, but
the lack of inheritance is its biggest language flaw.  Inheritance is
probably the biggest distinction between OOP and other programming
methodologies (eg. procedural & modular)...

--------------------------------------------------

VB, Delphi & SQL Development
Vancouver, BC.
(604) 689-2616
-------------------------------------------------



Tue, 21 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)
RE: Your Classes in VB4....

If you have the time, I'd really like to hear how you handled making your
objects persistent (i.e. in what format do you save the data, how do you read
the data back in and recreate the  class instances, etc.)

TIA!
John



Tue, 21 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)

Quote:

>>I no longer care, and it does not matter in the long run: if it is
>>maintainable, encapsulated and polymorphic (the speed class never knows
>>when it is invoked from code or from the Vessel class; the IsValid
method

>Not to be picky, but I think you've got this little bit backwards.
>Polymorphism refers to the ability of the calling code to execute a
>method on an object of an unknown type, and have the "correct"
>implementation of the method resolved by the compiler/interpreter.
>"Traditional" OOP languages use virtual methods and inheritance to do
>this, while you can accomplish it in VB by using late-bound objects
>(i.e. OLE objects created by CreateObject).

You are right, I worded it poorly.  The notio I was trying to convey was
that several of the classes I built have an .IsValid property, the calling
code knows nothing about the internals, it is the
class/object/compiler/Binary Gods or Magic that resolves it.

- Mike



Wed, 22 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)

Quote:

> * Classes and Objects *
> If you haven't toyed with these, I urge you to do so now.  They are Mondo
> Cool...

Thanks for the tips.  We also have switched to using VB4(Pro32)classes and the
reusability is incredible.  Did you also use collections in your boat insurance
program? If so, did you use the strict 'house of bricks' approach outlined in
the VB4 manual?  Any problems with collections?




Thu, 23 Jul 1998 03:00:00 GMT  
 VB 4, Classes and OO stuff (LONG)

writes:

Quote:

>> * Classes and Objects *
>> If you haven't toyed with these, I urge you to do so now.  They are
Mondo
>> Cool...

>Thanks for the tips.  We also have switched to using VB4(Pro32)classes
and
>the
>reusability is incredible.  Did you also use collections in your boat
>insurance
>program? If so, did you use the strict 'house of bricks' approach
outlined in

>the VB4 manual?  Any problems with collections?



I only skimmed that part of the manual,but I am familiar with the concept
of atomicity, and have written a modest amount of C++ code.  

So, I dont know if I 'strictly' followed it as they couch it in the VB
book, but I can tell you the classes share only CONSTS with the BAS files
and the only way to interact with the classes is thru Methods and Prop
Set/Lets.  I can also tell you that I was able to spin a class into a
standalone applet by adding a form and  one of the classes to a new
project....Mondo Cool! (sans cut and paste, by the way).

HTH
-Mike



Sat, 25 Jul 1998 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. OO and class question for vb.net

2. prob w var user defined type as class mem ( prob easy for an exp VB OO)

3. OO Class Design

4. OO Best Practices – table joins across classes

5. Visual Basic VB6 OO Classes

6. vb4.0 Book on Classes/OO - Comments anyone?

7. OO and classes - sorting problem

8. Beginner Question: OO or not OO?

9. OO for the non-OO programmer

10. Newbie to Classes and stuff

11. How OO is VB.NET?

12. OO Problem in VB.NET

 

 
Powered by phpBB® Forum Software