这两天在看设计模式,想在这边随便写点.
模式一.装饰者模式 Decorate
书中举的一个例子,就是卖咖啡的问题.
首先coffee 有好多种,摩卡,蓝山等等.
我们会定义一个基类class coffee
{
    decimal cost();
}
然后派生两个类
class mocha : coffee
{
    decimal cost();
}
class blue : coffee
{
    decimal cost();
}

这个时候顾客会有要求,我要加三份奶,两份糖,当然starbucks是免费的.
很自然我们会定义两个类milk 和sugar
class milk
{
    decimal cost();{return 1.00;}
}

class sugar
{
    decimal cost();{return 1.00;}
}

void main() //首先我们不考虑是mocha 还是blue,假定是mocha
{
    decimal(Mocha mocha,int milknum,int sugarnum)
    {
        Sugar su = new Sugar();
        Milk mi = new Milk();
        return mocha.cost() + milknum * mi.cost() + sugarnum * su.cost();
    }
}

接下来是用装饰者模式来实现
让每个辅料继承coffee
class Milk :coffee
{
    private coffee _coffee;
    public Milk(coffee coffee)

    {this._coffee = coffee;}
    decimal cost()
    {
        return 1.00 + _coffee.cost();
    }
}
sugar也是这样修改
然后我们看main
void main()
{
    Coffee coffee = new Mocha();
    coffee = new sugar(coffee);
    coffee = new sugar(coffee);
    coffee = new sugar(coffee);
    coffee = new milk(coffee);
coffee = new milk(coffee);
cost(coffee);
}
decimal cost(coffee _coffee)
{
    return _coffee.cost();
}
我发现在计算费用方面是方便了,但是对于,几份糖,几份奶还是不是很方便.

posted @ 2008-05-23 11:05 alwaysdotnet 阅读(17) | 评论 (0)编辑

Last night I had dinner with two friends,actually they are my ex-manager and new partner.
All of us are working in IT industry also in software but three different roles.So I think it is very interesting.

With the more competitive software marketing comes,IT is no more shinning than maybe 5~6 years ago,so same as we met before,we began complaining everything we hated in daily work in turn.

My ex-manager said " there are too much projects with low profit.Why" ,"maybe the cycle is too long and with time increases ,the cost is added eventually".

New partner said " it's very difficult to recruit experienced developer now because the time is not right,most resumes are from high school student."About my new partner ,he is a .Net MVP and has dedicated to do one thing for more than four years.My ex-manager & I both admire him very much,especially his perseverance.

Now it's my turn ,I compalin there's no challenge in daily work so I feel a little idle.
Qucikly they think I am happier than them .But in fact I don't think so.Sometimes we complain work is so busy,sometimes we complain work is so boring.We are all seek the balance point.A kind of work
that is rich but not too busy that could enhance you competitive ability and make you enjoy life also pay you a satisfied salary.Ok.after complain,we turn to our topic,we began to discuss our draft plan in terms of an existed system.We have no clear next step but we don't give up.We ask what can make us do better.The asnswer is ideal.Yes it is.
Ideal is a very important  thing,no ideal,no future.How big the ideal is ,how far you can go.

posted @ 2008-05-08 17:32 alwaysdotnet 阅读(27) | 评论 (0)编辑
今天无意发现一段代码
<META HTTP-EQUIV="REFRESH" CONTENT=2>
在msdn的解释是:causes the browser to reload the document every two seconds.
跟大家分享下.

与此同时,发现cnblog的一个bug
在标题里写上 <META HTTP-EQUIV="REFRESH" CONTENT=2>
会发现页面不断的被刷新.呵呵
posted @ 2008-04-15 14:12 alwaysdotnet 阅读(136) | 评论 (0)编辑
有的时候,我们会用httpwebrequest 去request一个页面,然后把内容全部输出,如果两个文件不在一个目录下,并且当被request的页面中存在一些
post 事件,我们会发现,输出之后就不work 了,这时需要,替换输出流的action地址,这样就行了,然后在post一次之后,你会发现,页面地址就变成本身被post的页面的地址了,然后css又找不到了,因为是在两个文件夹下面,所以你要准备两套css,或者把css单独到一个project ,这样就可以了.
posted @ 2008-04-14 10:09 alwaysdotnet 阅读(52) | 评论 (0)编辑
sql 2005 有个新功能assembly
发现用C#写的dll,和VB写的dll 在创建assembly时不一样.
posted @ 2008-04-09 14:38 alwaysdotnet 阅读(33) | 评论 (1)编辑