Which is best practice and why

Which is best practice

namespace test
{

Class xmlProcessor
{
   BusinessLogicLayer  objClass=new BusinessLogicLayer
   objClass.hello()
 }

Class BusinessLogicLayer
{
     private void hello{}
}
}

OR

namespace test
{

Class xmlProcessor
{
   BusinessLogicLayer.hello()
 }

Class BusinessLogicLayer
{
     internal static void hello{}
}
}

PradeepYadhavAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fahad MukhtarDistinguished EngineerCommented:
IMO it depends heavily on the functionality of hello() method!
0
Fahad MukhtarDistinguished EngineerCommented:
the best practice (regardless of the functionality of hello() method) is the first one as it more follow the Object oriented design paradiagm more than the 2nd one.

static methods should be avoided unless there is some requirement to use them
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
devsolnsCommented:
Yeah it really truly depends on what that method does and even how that class works.  Most often you need an instance of a class to make it work correctly.  Keep in mind that if you make static method it can't access instance data.  Also if that static method can access static members then you need to make the method thread safe.

There is no right or wrong it just depends on what characteristics your class needs and that is most often determined by functionality (for example I would not make a connection pool an instance class) but sometimes to simply make it convenient like,

double result = Math.SqureRoot(423);
is easier to use than
Math math = new Math();
double result = math.SqureRoot(423);
0
Alexandre SimõesManager / Technology SpecialistCommented:
Hi...

I usually don't use static objects on the BusinessObjects (BO) Layer just because It usually doesn't make cense.
On the other hand, my DataLayer is usually structured by static classes obviouslly with static members.

Why... lets see...

A BO object represents something that has members that are directly related with that object instance.
For example, I can have an object called Customer that represents a... CUSTOMER!!! :)
with some properties... lets say... Name, Address, BirthDate...
and some methods like... LOAD, SAVE, DELETE
None are static... they are relate to that instance of the object Customer.

On the other hand, on the DataLayer (DL), I'll have another object, also called Customer, thet will have 3 static members:
LOAD, SAVE and DELETE.
All of them receive an BO instance of the Customer object and do their work.
They are static because they're not attached to a specific instance of any customer object, they are generic, behave just the same with every customer instance.


This is how I use static members on a simple n-tier aplications... there are more complicated scenarios but this one is a good sample.
I'm not saying that you can't use static member on any other layer... even on the UI, you just have to see if it makes cense.

Alex :p
0
devsolnsCommented:
um thanks for accepting that rather worthless answer.

it has NOTHING to do with object oriented design.  a cite avoiding them but no reason as to why
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.