Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is best place to write common codes Static Helper class or Base Class?

I have to write large amount of code which is going to be used in three asp.net pages.

I want to know the key points so that I can decide whether I should create Static Helper class , or create base class for common codes.

I am agree that creating single helper class vs creating multiple helper classes must be a careful job depending on various things like performance etc.., but the question still remain same , you can think me as a smart coder that can create perfect number of helper classes.

I think I am going to use these code only from these three asp.net pages.

Thanks for all your answers friends, but I need more inputs, can you please send more specific points.

Thanks.

like image 670
Imran Rizvi Avatar asked Oct 20 '25 10:10

Imran Rizvi


2 Answers

If it is code that is being shared by all three ASP.NET pages and not by other code, a baseclass is a good idea.

The code is not exposed to the 'outside world' (by making the methods protected) and you define a context in which the methods should be used. They can only be called from an ASPX page that defines trough inheritance that it is-a certain base type where the methods make sense. A Helper method could be called from everywhere in your code by just passing the right parameters, even if this is conceptual invalid.

If it's code that's going to be called from different places (for example a ValidateEmail function) then a static helper class could help.

But if you opt for the helper class, you still have to decide how many helper classes you are going to create. Dumping all your helper functions in one class is probably not a good idea from maintenance perspective.

like image 195
Wouter de Kort Avatar answered Oct 23 '25 00:10

Wouter de Kort


Create a base page and inherit from that and then put your helper method and properties on the base page.

like image 43
Ben Robinson Avatar answered Oct 23 '25 01:10

Ben Robinson