Code reuse is a big concept in software development. But how many project teams understand as to how to reuse code effectively? Even bigger question is: how to do it?
Good software design is the first step towards ACHIEVING code reuse. But project teams fail to understand the design concepts which can go a long way in utilizing code reuse. For example, suppose you need to implement 2 different functionalities of creating a new record for a user and a user request for some service. These 2 functionalities are independent of each other. The database tables may also be different.
Now is it possible to combine these 2 functionalities in design? This will be needed if some code reuse can be done. The reality is that most project teams will never realize that it can be done. Thus they will never try to do it.
But it is perfectly possible to do it. How you can achieve code reuse here? First you create a class which may contain 2 methods: one for each functionality. On top of these 2 methods you can write the logic which will redirect a connection coming from some event to the right piece of code.
The benefit of such a design is that some more code can be reused if similar kind of functionality is required at some other places.