Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - Do We Need A Constructor If It Doesn't Have Any Logic

I'm working with Angular.

I'm wondering about whether constructors are needed, and would appreciate some insight. In several classes, I have constructor that are empty most of the time my service classes have empty constructors.

Can these empty constructors be removed? Are there any negative impact to a class have no constructor vs having an empty one?

like image 966
ineedtoknow Avatar asked Jun 24 '26 05:06

ineedtoknow


1 Answers

If you don't use DI (dependency injection) service for Angular in your class you can remove it .

If the class won't be used by third parties and you don't need an overloaded constructor, don't write an empty constructor.

like image 129
behroozbc Avatar answered Jun 26 '26 19:06

behroozbc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!