锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产高清精品线久久,永久亚洲成a人片777777,国产青草亚洲香蕉精品久久 http://www.tkk7.com/jedikings/category/12126.htmlzh-cnWed, 28 Feb 2007 07:42:44 GMTWed, 28 Feb 2007 07:42:44 GMT60Reading notes -- Singleton patternhttp://www.tkk7.com/jedikings/archive/2006/07/09/57330.htmlJediJediSun, 09 Jul 2006 04:42:00 GMThttp://www.tkk7.com/jedikings/archive/2006/07/09/57330.htmlhttp://www.tkk7.com/jedikings/comments/57330.htmlhttp://www.tkk7.com/jedikings/archive/2006/07/09/57330.html#Feedback0http://www.tkk7.com/jedikings/comments/commentRss/57330.htmlhttp://www.tkk7.com/jedikings/services/trackbacks/57330.html public class 聽Singleton聽{

聽聽聽聽
private volatile static 聽Singleton聽uniqueInstance;
聽聽聽聽
private 聽Singleton(){
聽聽聽聽聽聽聽聽
聽聽聽聽}
聽聽聽聽
聽聽聽聽
public static 聽Singleton聽getInstance(){
聽聽聽聽聽聽聽聽
if (uniqueInstance == null ){
聽聽聽聽聽聽聽聽聽聽聽聽
synchronized (Singleton. class ){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
if (uniqueInstance == null ){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽uniqueInstance聽
= new 聽Singleton();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
return 聽uniqueInstance;聽
聽聽聽聽}

}

1. private constructor
2. static getInstance
3. syncronized..waste a lot of time
4. double check..modified syncronize, so time-waste might occurs only when first time the instance construct


Jedi 2006-07-09 12:42 鍙戣〃璇勮
]]>
Reading note of "Head First Design Patterns": Strategy Patternhttp://www.tkk7.com/jedikings/archive/2006/06/13/52422.htmlJediJediTue, 13 Jun 2006 04:42:00 GMThttp://www.tkk7.com/jedikings/archive/2006/06/13/52422.htmlhttp://www.tkk7.com/jedikings/comments/52422.htmlhttp://www.tkk7.com/jedikings/archive/2006/06/13/52422.html#Feedback0http://www.tkk7.com/jedikings/comments/commentRss/52422.htmlhttp://www.tkk7.com/jedikings/services/trackbacks/52422.html聽聽聽Joe's company聽makes a duck pond simulation game, SimUDuck, The game can show a large variety of duck species swimming and making quacking sounds.

Initial Design:
diagram.JPG
But now some new functionality should be added, for example: we need some of the ducks to FLY.

First Design:
聽聽聽We add a method fly() into the Duck class. It seems worked, but something went horribly wrong because not all ducks can fly. so....

Second Design:聽Using inheritance and polymorphism
聽聽聽Always override the fly() mehtod in the subclass where needed.

test.JPG
聽聽聽

聽聽聽Drawbacks:聽Everytime a new duck is added, you will be forced to look at and possibly override fly() and quack(). so is there a cleaner way of having only some of the duck types fly or quack?

Third Design: Using interface!
聽聽聽test1.JPG
Drawbacks: It completely destroy code reuse for those behaviors.

1. Design Principles: Identify the aspects of your application that vary and separate them form what stays the same!
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 which means Encapsulate the parts that vary!
2. Design Principles: Program to an interface, not an implementation! (interface here means supertype! including interface
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽and abstract class!.. making use of the polymorphism functionality).
3. Design聽Principles:聽Favor composition over interface!

Strategy Pattern: Using Composition!
test2.JPG

Code implement:
FlyBehavior.java
publicinterface聽FlyBehavior{
聽聽聽
publicvoid聽fly();
}

FlyWithWings.java
publicclass聽FlyWithWings聽implements聽FlyBehavior{
聽聽聽
publicvoid聽fly(){
聽聽聽聽聽聽System.out.println(
"I'm聽flying!!");
聽聽聽}

}

FlyNoWay.java
publicclass聽FlyNoWay聽implements聽FlyBehavior{
聽聽聽
publicvoid聽fly(){
聽聽聽聽聽聽System.out.println(
"I聽can't聽fly");
聽聽聽}

}

Duck.java
publicabstractclass聽Duck{
聽聽聽FlyBehavior聽flyBehavior;
聽聽聽
public聽Duck(){聽聽聽聽聽聽
聽聽聽}

聽聽聽
聽聽聽
publicabstractvoid聽display();
聽聽聽
聽聽聽
publicvoid聽performFly(){
聽聽聽聽聽聽flyBehavior.fly();
聽聽聽}

聽聽聽
聽聽聽
publicvoid聽swim(){
聽聽聽聽聽聽System.out.println(
"All聽ducks聽float,聽even聽decoys!");
聽聽聽}

}

MallardDuck.java
publicclass聽MallardDuck{
聽聽聽
public聽MallardDuck(){
聽聽聽聽聽聽flyBehavior
=new聽FlyWithWings();聽聽聽聽聽聽
聽聽聽}

聽聽聽
聽聽聽
publicvoid聽display(){
聽聽聽聽聽聽System.out.println(
"I'm聽a聽real聽mallard聽duck");
聽聽聽}

}

The Definition聽of Strategy Pattern:聽The聽Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them intercahgeable. Strategy lets the algorithm vary indepanedtl from client聽that use it

Problems:
1. It's weird to have a class that's jast a behavior: classes represent things both have state and methods. a flying behavior might have instance variables representing the attributes for the flying behavior.
2.聽Be care聽of聽Over-Design: implement your code first, then refractoring!



Jedi 2006-06-13 12:42 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲剧场午夜在线观看| 999任你躁在线精品免费不卡| 亚洲毛片免费观看| 亚洲伦乱亚洲h视频| 成人免费视频一区| 51精品视频免费国产专区| 在线观看免费黄网站| 国产天堂亚洲国产碰碰| 亚洲欧洲日韩极速播放 | 亚洲欧美国产日韩av野草社区| 亚洲成人午夜在线| 亚洲一区二区视频在线观看| 国产成人免费一区二区三区| 中文字幕av无码无卡免费| 久久久久久久岛国免费播放| 久久国产一片免费观看| 黄床大片30分钟免费看| 亚洲av无码有乱码在线观看| 亚洲依依成人亚洲社区| 91亚洲国产成人久久精品| 婷婷亚洲久悠悠色悠在线播放| 国产亚洲AV手机在线观看| 免费国产小视频在线观看| 午夜视频免费成人| 毛片免费全部播放一级| 扒开双腿猛进入爽爽免费视频| 欧美三级在线电影免费| 日本免费网址大全在线观看| 国产卡一卡二卡三免费入口| 五月亭亭免费高清在线| jjizz全部免费看片| 91麻豆最新在线人成免费观看 | 亚洲va无码专区国产乱码| 国产亚洲大尺度无码无码专线| jlzzjlzz亚洲乱熟在线播放| 亚洲欧洲一区二区三区| 亚洲综合精品网站| 在线播放亚洲第一字幕| 国产精品亚洲产品一区二区三区 | 亚洲一级片在线观看| 国内大片在线免费看|