Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

shared classes and function in asp.net application

Posted on 2010-09-16
5
Medium Priority
?
421 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 668 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 668 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 664 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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