Solved

Bas and Cls oo technique

Posted on 2004-09-23
16
336 Views
Last Modified: 2010-05-02
Strange question.
Have seen some com component code where each the .cls methonds and basically just wrappers and call procedures in .bas modules. Apparantly this is supposed to help reusability? Has anyone come accross this before? Know why you would do it?
0
Comment
Question by:visual_b
  • 3
  • 3
  • 2
  • +3
16 Comments
 
LVL 11

Accepted Solution

by:
coopzz earned 32 total points
ID: 12132240
bascally it's to get an object orientated approach to something that isn't like the win32 api's.  and yer you'll see it all the time.

so what this helps with is creating a collection of related things that help do simular things, the Scripting.File System Object is a classic example. it's much easier to remember the object than it is all the procedure names.
0
 
LVL 18

Assisted Solution

by:JR2003
JR2003 earned 31 total points
ID: 12132261
It prevents all the source code being in the cls module and so helps with maintainability. The only access the external user of the com component is through the class module.
0
 
LVL 2

Assisted Solution

by:x_terminat_or_3
x_terminat_or_3 earned 31 total points
ID: 12132276
You can use classes to create new objects or to add functionality to existing objects.

The code required for the functionality of the class can be partly stored in a .bas file, specifically if the class module uses Api calls, the declares for them are usualy held in a normal module (.bas)


With kind regards



Ramses (x_terminat_or_3)
0
 
LVL 1

Author Comment

by:visual_b
ID: 12132309
COOPZ: But why not have the procedures in the .cls module?
JR: How does having the code in a bas module aid maintainability?
0
 
LVL 1

Author Comment

by:visual_b
ID: 12132328
x: But these modules don't contain any api calls? No reason that the code can't all be done in the .cls module. It seems to be a "style" thats being used...
0
 
LVL 11

Expert Comment

by:coopzz
ID: 12132338
sometimes you can't use the cls for doing certain things..

eg. if you building a dll project and you have more that one cls interface you may need to share a global varibles which you store in the bas files... and for the reuseability you can have some code that you use in different cls but dont' need to add it to all the cls

theres also that if your doing win32 call backs you can't use cls
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Assisted Solution

by:fds_fatboy
fds_fatboy earned 31 total points
ID: 12132342
This technique is used a lot if two or more classes both need to implement the same Method. You put the method functionality in a routine in a mod and the interface/wrapper in the class. Therefore only one set of code to maintain.

It must be remembered that VB versions 1 to 6 are not oo languages. In true oo you would be more likely to place the method in an ancestor class and inherit your other classes from it.
0
 
LVL 18

Expert Comment

by:JR2003
ID: 12132624
visual_b
<<"How does having the code in a bas module aid maintainability? "
If you have many thousands of lines of code it will be more maintainable if you have them in more than one module.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12132953
Sometimes there is an API call in the class that requires a callback method.  To use a callback method, you must supply the address of a function in your project but you can only do this with a sub in a module.

Regards,

Idle_Mind
0
 
LVL 1

Author Comment

by:visual_b
ID: 12133313
fatboy: If two or more classes use the same method, why not just make it a public method of a class, that can also be called from anywhere.
JR: Not sure I agree with you. Think all code relating to a particular entity should be stored in the same module, in an oo style.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12135486
visual_b
>>If two or more classes use the same method, why not just make it a public method of a class, that can also be called from anywhere.
You could  - I usually would. I was just explaining reasons not necessarily advocating them.There are advantages and disadvantages to usoing classes for everything. Thea main advantage is keeping your code where it is used is and highly maintainable, memory is not shared between instances of objects making it easy to know that your mod level variables are safe. Advantages of mods are classes are much slower to run code from than mods, memory is shared in mods making it possible to use AddressOf callbacks. You can't have a sub Main in a class.


>>Think all code relating to a particular entity should be stored in the same module, in an oo style.

Yes to a point - In VB6 is not oo. I have in the past used oo languages, and now again am again with dotnet.
With VB6, I personally take a pragmatic approach I do tend to put most of my functionality in classes and ultimately in DLLs - usually COM+, but some things I have live in mods - especially when subclassing controls.  
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12582431
Split points to all participants??
0
 
LVL 2

Expert Comment

by:x_terminat_or_3
ID: 12582456
concur
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now