My opinion--- for discussion, not for debate

jabber (jabber)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
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.
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
2001-8-10 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: A small design issue

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论