views:

55

answers:

1

I've got a BaseDataClass with shared fields and functions

    Protected Shared dbase as SqlDatabase
    Protected Shared dbCommand as DBCommand
    ...
    //also have a sync object used by the derived classes for Synclock'ing
    Protected Shared ReadOnly syncObj As Object = New Object()

    Protected Shared Sub Init() //initializes fields, sets connections 
    Protected Shared Sub CleanAll() //closes connections, disposes, etc.

I have several classes that derive from this base class. The derived classes have all Shared functions that can be called directly from the BLL with no instantiation.
The functions in these derived classes call the base Init(), call their specific stored procs, call the base CleanAll() and then return the results.

So if I have 5 derived classes with 10 functions each, totaling 50 possible function calls, since they are all Shared, the CLR only calls one at a time, right? All calls are queued to wait until each Shared function completes.

Is there a better design with having Shared functions in your DAL and still have base class functions? Or since I have a base class, is it better to move towards instance methods within the DAL?

A: 

In this particular case I would say no. This is not a good design. To even get this to work correctly every method call on every class would first have to acquire a lock on syncObj so as not to corrupt state due multiple threads competing for the same resource. Ignoring the potential performance impacts that may arise because of that, you would not be able to get your derived classes to work independently because they are all using the same "stuff".

I definitely recommend pushing towards instance methods in this case. If you still want your individual class using the same SqlConnection or whatever then pass it into the class using dependency injection.

Brian Gideon