PC Review


Reply
Thread Tools Rate Thread

class module and encapsulation

 
 
Dave Unger
Guest
Posts: n/a
 
      26th Oct 2010
Hello,

Being a relative newcomer into the world of class modules, I’ve done a
fair amount of reading on the subject (including postings in this
group), and one keyword that always seems to pop up is
“encapsulation”. While I can appreciate the reason for this, it leads
me to a question about how rigorously encapsulation should be adhered
to.

In my case, I have an application containing a few class modules, 3 of
which make calls to the same subroutine. I see 2 alternatives here:

1 – Include the common code inside each class module, which seems
inefficient, or

2 – Keep the subroutine outside the class modules, and lose
encapsulation.

Now, I have no doubt that my code is far from optimum, but it serves
to illustrate the point. Is “encapsulation” simply a guideline to an
ideal, or is it “written in stone”? I’d appreciate any comments/
advice on this.

Thank you,

Regards,

DaveU
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      29th Oct 2010
First of all, with things like this nothing is "written in stone"!

It sounds like your subroutine can be used without alteration by calls from
multiple class modules and can be regarded as generic. In that scenario I'd
probably put it in a normal module to be shared by all. However, if your
class module has the potential to be used as a ready made template that can
dropped into other projects, I'd probably keep such 'generic' procedures
within the class module, even if it might mean a little duplication.

One thing that is written in stone, fully declare all variables and head
modules Option Explicit

Regards,
Peter T



"Dave Unger" <(E-Mail Removed)> wrote in message
news:bcc496f2-b6e3-455e-9559-(E-Mail Removed)...
Hello,

Being a relative newcomer into the world of class modules, I’ve done a
fair amount of reading on the subject (including postings in this
group), and one keyword that always seems to pop up is
“encapsulation”. While I can appreciate the reason for this, it leads
me to a question about how rigorously encapsulation should be adhered
to.

In my case, I have an application containing a few class modules, 3 of
which make calls to the same subroutine. I see 2 alternatives here:

1 – Include the common code inside each class module, which seems
inefficient, or

2 – Keep the subroutine outside the class modules, and lose
encapsulation.

Now, I have no doubt that my code is far from optimum, but it serves
to illustrate the point. Is “encapsulation” simply a guideline to an
ideal, or is it “written in stone”? I’d appreciate any comments/
advice on this.

Thank you,

Regards,

DaveU

 
Reply With Quote
 
Dave Unger
Guest
Posts: n/a
 
      30th Oct 2010
Hello Peter.

On Oct 29, 2:18*am, "Peter T" <pete...@discussions.com> wrote:
> First of all, with things like this nothing is "written in stone"!


Oh, I know - I just grabbed the 1st expression that came to mind;-)

> It sounds like your subroutine can be used without alteration by calls from
> multiple class modules and can be regarded as generic. In that scenario I'd
> probably put it in a normal module to be shared by all. However, if your
> class module has the potential to be used as a ready made template that can
> dropped into other projects, I'd probably keep such 'generic' procedures
> within the class module, even if it might mean a little duplication.


Ok, I sort of suspected this.

> One thing that is written in stone, fully declare all variables and head
> modules Option Explicit


This one I do know, and is pretty much entrenched in my head.

Thanks for your reply, Peter. I just needed to get some feedback from
someone with more experience using class modules, just to be sure I
was on the right track (more or less). Very much appreciated.

Regards,

DaveU
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
running a Sub in a class module from a functionin a general module Paul Microsoft Access Form Coding 2 9th Feb 2010 02:25 AM
Difference between Form's Class Module and Class Module tobesurveyor via AccessMonster.com Microsoft Access VBA Modules 4 14th Apr 2006 01:08 PM
Class Module vs. Module - Philosophical Differences =?Utf-8?B?dnNlYWxl?= Microsoft Access VBA Modules 1 10th Aug 2005 12:29 AM
Convert Class Module to Standard Module =?Utf-8?B?TXVycA==?= Microsoft Access VBA Modules 2 26th Apr 2005 06:33 AM
VB hang when opening a class module (or form module) Antoine Microsoft Access 1 7th Mar 2004 12:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 AM.