`
xieyaxiong
  • 浏览: 39033 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论
文章列表
针对问题:在两个集合中的对象期望做到任意组合,而这样的组合的可能性是太多了,在实现起来无疑会导致类爆炸。所以必须有一种方法在运行时动态的创建出我期望的类型,有这样的一种解决方案可以做到:让两个集合的对象(装饰者、被装饰者)实现同一接口,也就是说让装饰者、被装饰者属于同一类型,并且在装饰者中组合这一接口,这样装饰者就可以组合(装饰)任意的被装饰者,更重要的是装饰完成之后的类型又可以作为被装饰者来被装饰,然后就可以一直这样循环装饰下去,用这样类似递归的形式就可以在运行时动态的组合出任意我想要的类型了。       装饰者模式结构图:           装饰者模式实现代码: ...

Goodbye and good luck

Goodbye and good luck         our neighour,Captain Alison will sail from Portsmouth tomorrow. we will meet him at the harbour early in the morning. He will be in his boat,Topsail. Topsail is a famous little boat ,it has sailed across the Atlantic many times. Captain Alison will set out at eight ...
   针对问题:在消息-通知 的程序结构中,为了通知待通知的对象,需在消息服务中持有所有的待通知的对象,消息服务和大量的待通知对象紧密的耦合在一起,无论是新添加一个通知对象、或是取消通知都必须改变消息服务。为了解决这个问题,消息服务(主题)必须提供注册和删除的接口,不仅如此,主题要想统一管理待通知的对象(观察者),所有观察者必须遵循某一规范,也就是在所有观察者中抽象出一个接口,主题无须打理观察者是什么,只要它遵循规范就行,这样就将以前的耦合进行了抽象,也就是松耦合。         观察者模式结构图:             观察者模式实现代码: /** ...
A good turn deserves another           i was having dinner at a restaurant when Tony came in. Tony worked in a lowyer's office years ago, but he is now working at a bank. he gets a good salary,but he always borrows money from his friends and never pays it back.   Tony saw me and came and sat ...
  针对问题:在许多继承体系结构中,经常出现的一些问题是在超类中的一些接口只需在部分子类中存在。或者是超类中的接口在子类中的实现算法大同小异,就那么几种方式,这样的话每当添加一个子类就不得不在已存在某个子类中复制粘贴,没有达到复用的目的。         策略模式的结构:           策略模式的java实现:   /** * 抽象类(将那些用继承不能解决的接口换成 用组合接口的形式实现动态改变形为) * @author bruce * */ public abstract class Context { /** * 组合策 ...
从概念上看     抽象类要描述的是一种类型,和普通的实现类一样描述着的现实世界的事物,不同的是普通的实现类描述着一种具体的事物,如三角形,圆形。而抽象类描述的是一种抽象的事物,如形状,动物等。   接口要描述的更多的是一种形为,如现实世界的事物所具体的功能和特点。实现类可以实现多个接口而具有多个功能和特点。     一种事物可能具体多种形为、功能,但是只属于一种类型。   java对抽象类和接口的实现上也和上面的概念相符合,一个实现类只能继承一个抽象类,而可以实现多个接口。   所以,如果要描述的是一种类型就应该使用抽象类。如果要描述的是一种 ...

Not for jazz

Not for jazz     we have an old musical instrument. It is called a clavichord. it was made in Germany in 1681. our clavichord is kept in the living room. It has belonged to our family for a long time. The instrument was bought by my grandfather many years ago. Recently it was damaged by a visitor. ...

A cold welcome

A cold welcome     on wednesday evening. i went to the Town Hall. it was the last day of the year. and a large crowed of people had gathered under the Town Hall clock. It would strike twelve in twenty minute's time. Fifteen minutes passed and then. the clock stopped. The big minute hand did not mo ...
The best and the worst     Joe has the most beautiful garden in out town. nearly everybody enters for the "Nicest garden competition" each year.    But Joe wins every time. Bill's garden is larger than Joe's ,Bill works harder than Joe and grows more flowers and vegetables. But Joe's g ...

Percy Buttons

Percy Buttons   I have just moved to a house in brige streat. Yesterday, a beggar knocked at my door.   he asked me for a meal and a glass of beer. in return for this. he stood on his head and sang songs.   I gave him a meal. he ate the food and drank the beer. then he put a piece of cheese on ...

No wrong numbers

No wrong numbers   Mr Scott has a garage in silbury and now he has just bought another garage in pinhurst.   Mr Scott can't get a telephone for his new garage. so he has just bought twelve pigeons.   Yesterday,a pigeon carried the first message from pinhurst to silbury. the bird covered the dis ...

An exciting trip

  I have just received a letter from my brother ,Tim. He is in Australia ,He has been there for six months. Tim is an enginee. He is working for a big firm, and he has already visited a great number of different places in Australia.   He has just bought an Australia car and has gone to Alice Sprin ...

please send me a card

please send me a card     postcards always spoil my holidays. Last summer, I went to Italy. I visited museums and sat in public gardens. A friendly waiter taught me a few words Italy. Then he lent me a book. I read few lines ,but  I don't understand a word.   My holidays passed quickly, but i di ...

Breakfast or lunch

 
Breakfast or lunch   It was sunday , I never get up early on sundays. I sometimes stay in bed until lunchtime. Last sunday,I got up very late,I looked out of the window,It's was dark outside. "what a day " I thought, "It's raining again'. Just then, The telephone rang, It was m ...
A private conversation     Last week,I went to the theatre.I had a very good seat.The play was very interesting.I did not enjoy it . a young man and a young woman were sitting behind me . They were talking loudly .I got very angry. I could not hear the actors, I turned round, I looked the man an ...
Global site tag (gtag.js) - Google Analytics