Solved

shared classes and function in asp.net application

Posted on 2010-09-16
5
406 Views
Last Modified: 2012-08-13
when is it appropriate to use shared classes. Are there any adavantages/disadv. to using non-shared functions.

For a data access layer would it be ideal to use a shared class. Please suggest.
0
Comment
Question by:TrialUser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Accepted Solution

by:
klakkas earned 167 total points
ID: 33691137
My rule of thumb is the following:

Use a Shared class if all the code that uses this class works under the same settings. This way, you only initialize the Class once and everyone has very fast access to it.

The example you use of the Data Access Layer is ideal. When your application wants to get data from a DB, if you don't use a shared class you would have to initialize the connection every single time. Using Shared Class, you only initialize the connection once and you can access it from anywhere in your program.

Finally, using Shared Classes reduces the coding.
With non Shared, you should do
Dim obj as new myObject
Res = obj.doWork

As with shared, you just say
Res = myObject.doWork
0
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 167 total points
ID: 33691142
For my data access layer I always use shared functions. I think if not neccesary to instantiate explicit objects of my DAL to call data methods.

Think in shared functions this way. Do you really need to create a instance of an object to call a method or function that doesn't need to use any data of that object itself?

Hope that helps.
0
 
LVL 7

Expert Comment

by:ajolly
ID: 33691146
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 166 total points
ID: 33691278
Well, part of my standard Data Access library is implemented as an abstract factory, which means static/shared methods for creating database objects. Ditto for specific data manager classes. A method that retrieve Customers from the database, for example, isn't necessarily going to benefit from being in a concrete object if it is literally only acting as a proxy for a database procedure.
0
 

Author Closing Comment

by:TrialUser
ID: 33781801
thanks
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filtering a datagrid view 8 34
vb.net datagrid scroll automatically to the first found row 11 28
parse string in c# 5 31
YouTube API get the Video Tags - vb.net 7 33
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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