锘??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 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 中文字幕亚洲精品| 亚洲综合伊人制服丝袜美腿| 国产免费爽爽视频在线观看| 亚洲美女视频网址| 成年女人永久免费观看片| 久久国产美女免费观看精品 | 免费精品国偷自产在线在线| 亚洲AV成人精品日韩一区| 中文亚洲AV片在线观看不卡| 国产精品永久免费10000| 黄色网址免费在线| 久久久久亚洲AV片无码下载蜜桃| 午夜视频免费观看| 成人片黄网站色大片免费观看APP| 亚洲高清中文字幕免费| 亚洲一区二区女搞男| 成人黄软件网18免费下载成人黄18免费视频 | 亚洲网址在线观看| 日本免费中文字幕在线看| 成全动漫视频在线观看免费高清版下载 | 在线视频精品免费| selaoban在线视频免费精品| 亚洲中文字幕久在线| 久久久久亚洲AV成人网| 在线精品免费视频| 久久精品免费观看国产| 97性无码区免费| 国产精品成人69XXX免费视频| 亚洲专区一路线二| 日本亚洲成高清一区二区三区 | 亚洲国产精品嫩草影院在线观看 | 91亚洲精品麻豆| 亚洲中文字幕不卡无码| 日韩中文无码有码免费视频 | 亚洲成A∨人片在线观看无码| 国产亚洲日韩在线三区| 成人永久福利免费观看| 中文字幕无码免费久久99| 久久99国产综合精品免费| 久久精品成人免费观看97| 精品久久久久久久久亚洲偷窥女厕|