Tuesday, August 30, 2005

IConvention

Micah Martin có post bài về IConvention . Đọc tức cười quá :))

Vấn đề đổi một interface thành class, mình cũng đã gặp vài lần rồi và cũng thích cách đặt tên của Java nhiều hơn. Việc chọn lựa IConvention chỉ có một lý do duy nhất là để phù hợp với cách đặt tên chung của .net framework mà thôi. Có lẽ cũng phần nào hiểu nỗi bực mình của Micah Martin.

Một đặc tính quan trọng nhất của OO là cho phép trừu tượng hóa. Một áp dụng của trừu tượng hóa là xem các interface như là khế ước (contract), hay từ dùng khác là protocol - nghi thức truyền thông. Interface là bộ mặt của package và "xứng đáng" có một cái tên dễ đọc. IList, no, List vẫn hay hơn nhiều và biểu cảm hơn :).
...
But wait! ICommand is not longer an interface. I can't just leave that I sitting there. Clients will think it's still an interface. So now I need to rename the class to Command without the I. Fortunately, ReSharper will help me there. But now I've got the Command class in a file named ICommand.cs. Renaming the file is a bit more challenging since it has to be changed in source control as well. So I rename the file in the subversion repository, then remove the ICommand.cs file from the Visual Studio project, and finally add the new Command.cs file to the project.... *whew*. That silly I sure causes a good deal of hurt.

No comments: