Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to have unused Components in project?

Generally unused/dead code is bad but I wonder what to do with unused components. Imagine that I have application that sends notifications to users, it sends EmailNotification but after some time we switch to sending notifications with SMS. Instead of deleting EmailNotification class i create interface let's say Notification and I have such structure:

Notification
--SmsNotification
--EmailNotification

I don't want to remove EmailNotification, because after some time we can go back to EmailNotifications and this change will be as easy as mark EmailNotification class as @Primary. In such case one of the implementations is always dead code and I wonder if it is ok or generally how to deal with that?

like image 591
swch Avatar asked Jan 28 '26 05:01

swch


1 Answers

Actually this is not the best practice. Instead of this practice, you can separate your code into two different modules, one per component. By this way you can utilize any of two modules depending on your needs through your build automation tool (maven or gradle for example). So the produced jars will contain no dead code.

like image 52
Anastasios Vlasopoulos Avatar answered Jan 29 '26 19:01

Anastasios Vlasopoulos