Wednesday, August 25, 2010

Replace 'Introduce Local Extension' With 'Extension Methods'

Introduce Foreign Method(IFM) and Introduce Local Extension(ILE) are two refactoring techniques that comes handy when you need to add functionality to an exisiting class,source code of which is beyond your control.
IFM is used when its just one or two functions that you need to add to the class.When the number of functions,that are to be added are more,then ILE is used.Not a rule though :)
But now with Extension Methods the whole process is much more simpler.
You need not do the subclassing or wrapper technique of ILE.
This can be a third way of implementing ILE :).Thanks to the framework team for keeping it simple.
The same date example using the 'Extension Methods' way of refactoring
  public static class MyExtensionMethods
{
public static DateTime NextDay(this DateTime date)
{
return new DateTime(date.Year, date.Month, date.Day+1);
}
}
The function NextDay is now available on any DateTime object,just as if you have written if you had access to the source code. It's the usage of ILE and IFM that has paved way for the inclusion of Extension Methods in the framework I guess.Thanks to Fowler for that.

Monday, August 23, 2010

TDD and Refactoring

Over the days I have been reading on Test Driven Development(TDD) and it seems really interesting methodology to go with as per development is concerned.
Basic of TDD is that the development process relies on 'tests', that are written prior to code.
Sounds astonishing!!!!
It might to someone into the normal development mode,where tests are usually written after code, so as to match the code that is written.
But TDD says just the opposite.
Code to make the tests pass...Just pass..Nothing more and Nothing less.
Thats where the catch is where most of we developers might find it difficult and needs getting used to.Not getting more into it as I would not be the best to comment on it :)
So whats refactoring got to do here.
Refactoring plays an integral part of TDD,so that the code is elegant and conveys just what it needs to,avoiding duplication.
The TDD approach also assists in refactoring as you have tests readily available to assure that the functional behaviour is not affected while changing the code design.You are just click of a button away if you are having a automated test scripts (like nUnit) in veryfying refactoring.
So both TDD and Refactoring goes hand in hand and helps in greatly improving the overall code quality.
There are quite a lot resources out there on these.
The best for refactoring would be of Fowler's.
For TDD this would be a good start and also the one by Kent Beck

Friday, August 13, 2010

Mission ASP.net

Its been high time I have been into windows developing..wpf mostly..I think its long enough to get a taste of the web too..thats whats hot and cooking...i guess..coz everyone is asking that.So I think I should take the plunge into it...the sooner the better.
Bluffing away @ interviews saying i have theoretical knowledge in jsp(was trained in Java quite a while ago) blah blah blah... doesn't seem to work I guess...they say why U when I have someone having work ex in ASP itself :)
Good Question!!!

So I am on this mission...to learn ASP.net..hopefully :)
edit:
Got hold of some books..let's see how it goes