PDA

Click to See Complete Forum and Search --> : [RESOLVED] DLL - Class or Module?


MarMan
Aug 5th, 2010, 11:34 AM
What's up?

I am creating a couple of DLLs and was wondering on what others' opinions were.

I used to create DLLs with classes. I just made one with a module, works well.

It actually seems to be the best choice if the DLL is going to encapsulate functions and not really relate to any one specific thing (object).

If you use a module you don't have to instantiate it. Making a class and marking every public method static seems silly, no?

Any opinions?

techgnome
Aug 5th, 2010, 11:51 AM
Making a class and marking every public method static seems silly, no?
No, not really... because 1) that's what's going on behind the scenes anyways... 2) the concept of a module is VB-specific... C# doesn't have anything like it (short of doing it all by hand). So in general terms of learning OOD/OOP ... no, it doesn't seem silly, but logical. The use of a module file simply takes the mundane out of having to do it yourself.

-tg

MarMan
Aug 5th, 2010, 12:05 PM
So tech, you think it makes absolutely no difference whether a module or a class with all its membres static is used? Or is it better to use the class since that is what it really is anyway?

techgnome
Aug 5th, 2010, 12:10 PM
It makes no difference. If I remember right, the MSIL that's generated during compiling results in the same thing. I just use a class because I'm usually refactoring from an object into a static library, so I'm starting with a class in the first place. And those few times when I know I'm working with static functions, my initial instinct is a class anyways, I rarely give modules a second thought.

In short, it doesn't matter either way, and there is nothing wrong with modules.

-tg

DeanMc
Aug 5th, 2010, 03:31 PM
Oops, read it wrong. TG is right, a module is simply a VBism.

techgnome
Aug 5th, 2010, 03:37 PM
huh? you said that they are the same but not interchangable? Eh? You lost me. A module is in short a static class with static members... right, you can have only one instance of either kind (and I'd even argue the use of instance, but that's another subject)...

If I've got Module X... it is static, as is all of its members. If I have Class Y, declare it static and all of its member static... what's the difference? Nothing... they are essentially the same. No difference. What is different is a class (non-static) that has all static members... now, it's not quite the same, as that class could be instanciated (except then there isn't a reason to, since all of its members are static, any use of them will result in an error.)

-tg

DeanMc
Aug 5th, 2010, 03:57 PM
Yeah, I pretty much read it completely wrong!

techgnome
Aug 5th, 2010, 03:59 PM
OK... just checking... didn't know if you were smoking something, or knew something I didn't... figured either one was a plausible circumstance. :D

DeanMc
Aug 5th, 2010, 04:01 PM
Combination of work and tiredness actually!

jmcilhinney
Aug 7th, 2010, 11:57 PM
the concept of a module is VB-specific... C# doesn't have anything like it (short of doing it all by hand).A VB module is equivalent to a C# static class. If you declare a class static in C# then declaring a non-static member will produce a compilation error. The two compile to the same IL. The module concept in VB is in keeping with VB6 modules.