Thursday, November 15, 2007

Custom or Standard?

Modern languages like Java, C#,... provide powerful APIs with many libraries which are ready to use. But sometimes I consider I should use the "standard" class or create my own custom class. Spending more time to think about it, I realize that it depends.

Assumes that I want to have a list of members, if I use Java, I can use List<Member> or create my own MemberList to store all members. If I want to have more features than the standard List<Member> provides, of course, I need to create my own MemberList, which bases on List<Member>. But what will I do if I only need a read-only list? A List<Member> cannot do it. To have a read-only list, I need to use Collections.unmodifiableList(myMemberList) or create MemberList which supports read-only only.

Now consider that I only need to use the read-only list inside my application, which solution can I choose? One of two but maybe one of three. I also can use List<Member> and forget about its "edit" methods.

To have a clearer design, using MemberList will be the best solution but it needs time to implement. To be lazy, using Collections.unmodifiableList(myMemberList) or List<Member> without using its "edit" methods is an acceptable answer.

No comments: