|
-
Redundant code
I often have different classes in a project whose methods rely on standard
routines. For example, I'm working on a project now that has two classes which
uses bitwise operations that are contained in a module called modBitWise.bas.
One of these classes is project specific while the other could be used in future
projects. Do you consider it prudent to duplicate this code in the reusable
class so that it can be standalone? Otherwise I'll have to make sure that I
include modBitWise.bas in any project that reuses this class.
-
Re: Redundant code
One of the main purposes of a class is to hide the details of functionality
behind a set of defined interfaces (much like an ActiveX object's purpose).
The class is like a black box; the consumer of a class shouldn't be bothered
by the insides of the box, including any dependencies required by the box.
While this is a great goal, it can lead to some inefficiency, such as the
duplicate code issue you mention here. You can call global functions from
inside a class. In fact, the presence of the Friend keyword almost begs
the programmer to have classes interact with each other.
You could place the bitwise functions in a DLL of their own, and make that
DLL a dependency of each of the two classes. In that way, it could continue
to be a dependency for the class that will go on to future projects. Still,
that seems like overkill for the type of work you are describing.
If I was in your place, I would probably duplicate the code in the module
that you plan to use in other projects. It would be hard, and my hands would
shake with each copy and paste of the code. But this would have the benefit
of giving the class that true black-box feeling. And, isn't that was every
class really desires, deep down in its heart? :-)
-----
Tim Patrick
tim@vbstyleguide.com
Similar Threads
-
By Phil Weber in forum .NET
Replies: 632
Last Post: 10-01-2003, 12:00 AM
-
Replies: 150
Last Post: 03-04-2002, 05:40 PM
-
By devi in forum VB Classic
Replies: 3
Last Post: 07-09-2001, 03:25 PM
-
By Steven Bell in forum .NET
Replies: 260
Last Post: 06-01-2001, 04:32 PM
-
Replies: 90
Last Post: 04-17-2001, 12:45 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks