Convert code into controls, make life easier

Code re-usability is an important aspect of Object oriented programming but mostly it is taken as inheritance and polymorphism only. When you come across a unique requirement, you think over it, get to solution and implement it. This particular solution is very specific to that very problem. However there is always a chance that you could implement the same solution for the same problem in a way that it could also be used for some other case but with a little bit of tweaking or even by addition of values to some parameters. This is what computer science is all about generalization.

Let’s consider an example. You are a C# developer and you are writing an application, let’s say an HR Management System. The system has a lot of data validation, emailing facility, document uploading and even a virus scan. You want your system to catch any exceptions, do any exception handling work and sideways make a log of these exceptions. You wrote a class which would take an exception object as an input and write it to a text file on the machine as well as email it to a certain support email address.

A few days later when you are working on another application, you need similar exception logging. What is ideal here is to go the previous project. Copy the code of exception logging class and create another project and add the same class into it. Compile it. Add a reference to its output in the previous (HR Management in this case) project. Now you will replace the references of the older exception logging class with this newly added external class. Using a re-factoring tool like ReSharper is a good idea here. Sideways you will make necessary changes in the external class to make it generic.

Now you will return to that new project again and use the same exception logging class reference here as well. Life is a bit easier now.

LinkWithin

Related Posts with Thumbnails