The Art and Process of Reusability in Software Development
September 20, 2009 2 Comments
Reusability is the art of planning and developing application components so that they can be easily reused in other areas, be easily built on top of, and provide a decoupled approach to development and testing,
When developing software and writing your code, a great amount of care has to be taken into consideration on the subject of reusability. The first question you should be thinking about is:
Which components do we have available to use that have already been developed?
So, we’re thinking about which components or software code that have been developed already that we can reuse (either within the same application or a new application). Components in this context, could mean any of the following scenarios:
1. Code that we have available that wasn’t necessarily designed to be reusable:
This is code that we may have developed within another application without really thinking about it’s reusability, and even though it wasn’t designed to be reusable we can still harness the value of the code. Depending on the situation we could abstract the code from the original location and make it reusable – this would be important to do if you can really see this piece of code or component being reused again and again. This requires modifying the original code or component and the application using it in order to get the abstraction. The original application will now use this component and your new application will be reusing that exact same component. Improvements to the component could now affect both applications.
Another option is the good ol’ copy and paste method. Bad, Bad, Bad! Well sometimes it’s bad – not always. Go in to the other application, select what you want to copy, and paste it into the new application – modify as needed. Presto! We’ve all done this, and it can be justified if the effort required to copy/paste/modify as many times as you project you will ever need this code is much less than the time it would take to decouple it. Sometimes you may just do it to be lazy – hopefully if you do it due to laziness it doesn’t bite you in the ass the next three or four times you want to re-use the same code again – wishing you’d have decoupled it from the get go.
Sometimes, you may have code or components that you want to reuse but you are having difficulty decoupling it from it’s original source. Reusability wasn’t taken into account when the code was originally written and it’s too tightly coupled to the original application. The reusability factor here is lost and typically you have to duplicate the effort and re-write from scratch into a new application. Now, hopefully the second time it gets written – it’s designed to be reusable.
2. 3rd party components we can plug into our application:
There are tons of time saving components from 3rd party vendors out there that we can plug into our applications. These components typically provide functionality that is not native out of the box functionality for your application. Some examples of available third party components are: Data grids, ORM mapping, charting, reporting, etc. These can provide an enhancement to your applications that will save you development time in exchange for the licensing fee of the component. Purchasing new 3rd party components can be time consuming as you want to do an extensive search and evaluation on competing components from many vendors before making a purchase decision.
3. Using free source code or components found online:
There are many great source code examples and free components available online that you can plug into your application. These can be a real timesaver, but typically should be thoroughly tested before production to a greater extent than other components as they typically provide no warranty and can sometimes introduce very unexpected bugs if you are not careful.
Ok, so you’ve thought about the ideas above but still feel you must begin development with new code – you now need to think about future reusability of the code you are writing.
I’ll get into more detail about developing for reusability in Part II of this blog posting. Coming Soon!