My opinion--- for discussion, not for debate

jabber (jabber)
<本文发表于: 相约加拿大:枫下论坛 >
1) java.util.Hashtable is a utility class. In any case, it is a bad idea to have your business class extend a utility class. Indeed, ShoppingCart looks like a hashtable. The more proper approach is to let ShoppingCart use a hashtable. By doing so, one can also hide those not-wanted functions of hahstable (it has a lot of methods and ShoppingCart does not need them).

public class ShoppingCart{
private Hahstable contents = new Hashtable();

This is the so-called Delegation Pattern. It is used everywhere in Java.

2) The patterns are a good thing. Usually, people like to follow some patterns. However, poeple may also play against patterns. In the software industry, there is a school of ANTIPATTERN. Both the life and software are complicated. So it may be possible that sometimes a designer finds a good reason to use anti-patterns, to say, writing a business class by extending a utility class. Whenever we see something unnatural, we have better try to avoid say other people are wrong. The best words is " I don't understand...."

3) I am not working on ChoppingCart now. Actually, I am working on healthwell and created the above problem according to the real one in my design activity.
<本文发表于: 相约加拿大:枫下论坛 >

2001-8-10 -04:00

回到话题: A small design issue

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论