Oct 25
Let’s look at a method written in Java:
void printMyTransactions(MyAccount myAccount) {
Currency currency = myAccount.getCurrency();
printTransactions(currency.getFormat());
}
The problem with this method is that it shouldn’t know about the existence of Currency. In other words, our method doesn’t own an instance of Currency. The fact that MyAccount has a Currency in it should only be known to MyAccount itself. So it’s better to write this method as a delegation:
void printMyTransactions(MyAccount myAccount) {
myAccount.printTransactions();
}
This is the Law of Demeter for functions. It states that any method of an object should call only methods belonging to:
- itself
- any parameters that were passed in to the method
- any objects it created
- any directly held component objects
Following this law will help reduce the coupling in your program. I already see quite a few places where we can apply this law in our project.
Oct 25
Recently, there has been a couple of articles criticizing Agile methodology floating around on the internet. I’m sure there are same kind of stuff before. But I just noticed these two because I happen to read Joel’s blog.
Having worked on two Agile teams for the last four years, I have to say that it’s the best four years in my career life. I’ve been living in a perfect world where everybody is Agile. You can imagine how mad I was when some people dare to challenge my “religionâ€. I have to strike back! But before I could do that, there he is, Martin Fowler, my favourite Fowler in the whole world. In his most recent blog entry, he talks about Agile Imposition, which is a way more rational view on Agile. One of the things that I strongly agree with him is that Agile is people oriented. It adjusts the process to follow the human nature. It makes developers happy. The happier a developer is, the better he/she is.
Of course there will be problems. But most of the time these problems exist regardless of what process you are using. How many projects failed because of the methodologies? Both articles above mentioned the cancellation of Chrysler’s C3 project. C’mon, don’t you have to define failure before you say something failed? This is especially true in software development. C3 project went live, didn’t it? And how did the first waterfall project go? Nobody ever said Agile is a silver bullet except the people who are trying to make it look bad. But before you do that, try living as a developer in an Agile team for a couple of months, OK?
We should all thank Martin Fowler for standing out on this one. Go read his blog. He’s a way better writer than I am.
This was written at Vancouver airport on October 6. The posting was delayed due to the lack of internet access.