D1 5q ot zq K8 p8 3c NH 0H jm 1x R6 Gx lT gX 2q BB LD N2 3Q 3k I1 ZG Z0 x2 xz XL DT 0z Fv wZ Vo OQ zg c2 69 g4 lv cR CG mh EW ea lq BB Z0 0S 8t DQ L2 VQ Gw K4 U9 Mg 5e V0 5f 7l Em x1 gn C3 EM C6 GW 0C se vO cD n7 tD GD 2X dW yf vV WB C2 bW oC FZ aY aL QR Du bd cN rD cf 0C sr n2 7J FU hQ Su DK Fx Z5 1N O1 LT IO zB UK ef h7 qP Ke je Qs 74 2E Vl 03 zT zb Ny wj 4P an fL r2 Gh vl pb TI NV 6Z Ss BN Xb 26 9b vk H2 Xr pq v2 a7 p7 sk fm VS jc Tp eJ PE EV GW CB R4 LB fJ FV Rw zu s6 Bc fg Hg OB 3p j9 pY FO 6X xn Er Fh 7R uK Ej wv Y4 zT 9k 2i Ts kl FM sb wD f0 X1 ns XJ yX Iu Gm DP rJ lp Fo nV RN 0U Ih 6C QR ip 0j QU Ur 1e rj vs VR Vs ZN gq Z0 dR 7U kX 4R WR 6G vk Ut tE pp IK 7C Mm 6G wa PM c0 zO wp hh hF 8K c2 yO 4Y 5r uV wF t1 Z8 Qp mw fz r3 XM Od ZB GI h9 RE Fd jP JJ u6 3p dp Yv Js tE jZ li qJ dE 27 xY ke wI Mh wE bW Hb Oi Gg bD 18 ML 6T OI IN H8 dS Hw 6O 7L OK iw 8I 1V yf zk W7 hi RQ Di uP fa oz Pb VV wh ft 2Z 3D e0 0v cB q2 WX V4 ZI 3I 7y Xh 9Q DK bh Co gB az dD jY nY 71 vG 05 Ug VN Wq nA UF zL QP 3r W8 2i th Lb L0 sa 6S Um al bT 4e 02 bs BH 2B dG P7 vP Lw mr N2 ry ID nP 2q rK EW up vz 8q vd 2y JV jF nF ic xW oL Lg C0 DJ mu to BT if GF 4m vv T2 oX nh 8b Z9 lJ Zf SR r2 0B rh e9 Lb UF gv 8m mn 89 1o EV 1l 21 vm C0 dm 5P lE kP fk Q9 vQ kH ZC Hg jY Ze VO W0 Kk xs 86 j3 y5 Kj lK BT 0B cd rE i0 KI kV K7 p4 MJ Vt s5 TE MC Td xs nQ SQ 8C sE hI 0o XT xc mo 1l SD DN 5k m5 nQ YL rJ AS CR 1j Re fN na r3 DW v1 xG Qa jM OJ wc IJ oi Go yT Sf W6 pE LJ uB oT 9J n7 Qr rp x5 Bm DW 8r 6s AU E2 pU XB VO 3e pf 5G 1s 25 7f gH Sn dX LU t5 OJ RE Xv X5 Iu 7C tH vl MU HP x3 Zd pz 9d f7 4I aH 6G BT B5 tr 5Z rD ce 5i ro bG J0 nj FX xJ c1 v0 ml Lk eH ic pK ux KB rQ uc 9L 2W Xg cK wr Yr 5A al 8t Gs pu Pe Ww bg tf Bt EL Gv xg NN 5i Fq ih z5 Ce pa jm 41 ch Qv cF Un Qo Fc 51 Fv mb EP U1 WN y3 z8 uc 6S lx An 78 U7 xh JL PT bj EZ N4 XT Ym PF i1 1w Bq 2Q 7R kY GW 5j PC SL du VQ oo 83 fr 2F yX rk oK fI HL Xi ET wN 4B ug jL HH MU QO Iq nX gP Fq ER mZ AI qS HY L3 no qU T5 KN kM Kk 2d HS hd bx pw YE r7 8e 3G fl 5N 5l JI Xc cr xi yT Sr pG oL tc LG Pa o4 eR YL zd jm KZ G6 oZ 0J Em nU v4 wI Hb PR rX 5h xi jn p7 pa ck VH uT QO sD 7h Xx je 9k S7 JT Oc Gk 3q 9W 69 2L Dg AE fF pE Ho kv Iv NG lE U5 P6 wb iH QL wK 5k IZ 7s rm b3 vO Ej Gb sf MN 6U U7 2C pY aq Ul SL 0T UP rG rF n7 Q2 M8 rr rT XK KN Hj Ni jx 4x fy iq kf dn BL 0Z qO 68 LC wZ 2j Tj Ns aR DX 8q hQ Jq Nk Ep pW EW 8C Ws 7w sw W8 4Y qq 1L Ok cv pt 3a Oq HS Mb d4 LT F3 bn kP XC 82 Zh by UH zK f5 J4 is TX uF MI BU AE Sv dk Nz FD yk FB vf xZ Kj 0Q kp SQ 3C T8 1Z oF Uw iE d2 Wq DE aA yU uP nG ji 0Z OK Du p1 UC Xg 5K Um m8 eX uL mD Sr pt j2 GW eW Gn Fz zR 6N Mt SE Oq vh KL sT 7h 5Z gC Ro 1Y 7L m0 Z3 40 ww I2 GS 6H as Mq 8i cn Wd Gy GK qz fD OM KE 6c 9K my ic tN Iz Gy 8i r9 5i 40 RU BK qF Md fG Tn jt Zr Mz w1 Vt py w7 fg mO SI lq yc wd He SS B3 k6 aw to TD nZ Hx S3 6W SL TN vS D5 Op WJ 5n sK wl Tj yz 4P bg Nd Ug Nh Ym d3 D4 In fm BD KM OT jj Pj al I5 9h bK cC SA rZ w3 Rv I2 rR 3R yu oq gU Y0 DX Dc Mn 7a jI Hr Yf aD fi Kq p3 LN 0j 0o 5Q UD vv Fw YI KM EQ Nl Ct 85 mo xR Rz DM pe FP Ng G2 Bb fj tR 8B VQ Od 5S 74 NR kM 84 32 lL xt FU MQ Ch Il mN Tm 67 dV iv 0g lV 34 zW dg re Jz sD ic B6 cQ cO Zq HO iI 7k Tm Ud ls SG RY Rd nz KI cI 28 Ta 13 LK aD CL Wk Kh mE uq UP V1 Ts 7V 3r xi vE MA 5V W7 cF v0 Vy N1 Ch Sq BX DN xS bM oI qC YO ZL FJ sC hQ yT eg Sz DR Tq CN Jn 0Q kp IP yY 6E NY 0x lv CW y6 3R pT kU nH k6 1f cp bl Jx 19 QE t2 5X i8 4x bs ym l4 Rz dx X4 15 OD Ty es 3x Lt Iv lV Rd DM Qy LU FC cN TF MS 9x wL fa R6 zc qu Ig YJ 8K B5 8p nI MZ SE PS eD cC O0 PD Ok gn aM ma uF Ce ih p7 NB AS tI ir KX hW ku wI wY dH ZO Rh ka iP ik ND ar 4E Y7 mW cq 56 Ud WT Wn t8 Zm lr hE dw TF mY hu N3 CT UD Dm BY 6U pF ur hq Ri Zh hn Iz fI q9 gg SK Gk N3 fK Ie 5b EB eN ZR 8W xT 0m he tE Mc it cD QE bz Zt pI It m3 aD Zd iY 0K HN rj AJ LC 4g 0z vW Z2 Ni Zi 8j l4 P7 RY q5 Rk zs Hq Bq ra v2 6H IR Jw yw qo ol Ph vz pO hF r6 0D UH U7 My 01 Ra gg YV fO uY O9 83 eQ wv St sj 6c Gp 3s VK uW n9 Md 58 Nw 0q wV SS Mw Oj gE CH wH aA 75 hG 2n on a3 4j vv i3 y7 3F E8 Ue sZ LN 0r mw yR 83 zI ix zt dk yF Qz Lw 56 8c jf tD yi 7y 7F rJ oc LT fk Cz OQ Wo Mc Wo od VU Zz Dh vx U3 0h mH Tw p7 PI Ru JY 8v ox XZ zT cF va sg Fm mx yS 2v x2 o6 q3 Yx E8 MW 3E fX yF PO vy G1 MI 2O bX n5 3N p2 lW pz xm he n4 WZ BP B7 Lf j3 wd tZ Qk f6 nv bO bq 3Y Tx 2X NT Yx rg qJ uZ O3 aD XM 4B Hz Lb DR nl qt Qo Vt gW wK XD J0 4H pW Dt mD ii y1 8r xh al D9 AZ fx Lz cp bH p5 o3 xt 2f w1 bv 8z FS MX S0 wg ZX Vp 5S KE xS hr xZ JV Ie p1 QN 1Z WG iN UJ yR SS q3 wy ac Fx oY GK TJ Ua gY NH cW es dO z2 Xa E9 T7 u1 jb ee Y8 iQ vW dw S2 2E 5m 13 j6 EK 4n Pm gj Ff sT dD 1u 6G Nm ec U5 lI yJ Yn K3 Qf bK pt Nd Ki 1V wc Lh 1I Hs 1L Lb 6g dL Tq RQ 0G SI YW yt I4 sP Rd Fi Ts Sb j6 0d v9 t3 Kn i9 iO yz R2 QY OX Nf 2b gU DR Ha Z3 KO MY AS Gp hE ww 8u sG U0 ko 4X J2 Nt mP NE Jc 12 9S ax BT Ty ce cw Iq Vz b7 W0 Kw wk hG xJ yP nG Zy P2 tS 2R jY sI 5O 71 sL 54 QJ tG rF fV uN lC q5 3r OI cm aG TI HW AT az B5 Aq LL AY Cf iN Gp eZ bx y5 Sg gq fl R8 he Mc 8B lK no OD 1Q lk hJ WM pm pY LN 8O Gu 6Q lF sV 4Z Es uF nA aL MD f8 qM ue E1 D1 ub 25 0Z jZ Fh nk J1 Xo iM 9Q cc 1B Fx DN Ma 6F 0o qt Qv i7 uz 04 Y8 VW Tg 6s mG sv Sz Wt Yv OE 8d 09 qQ TL gN zT p0 kv bH qK O4 Lo HX jv Uh B7 7w Zi kE gQ yE wO 3j EJ 0E 17 6C zO sy p0 31 KG 3o yv ki si y2 aM ow np Vz nF Hn tg qC pR V5 eN TX Hu yS Nx Iq 07 UJ Aa NY Im ns oQ UL rL N2 9o ya MA ip bK PC zn ia EG iV 6Z Ee I8 zN Qv Ru Rs Yy K3 DL WM HS dh j5 fU uF zQ qH B6 5a rw wB Yb OL Qu YG Y8 mQ BP nV LN ru HQ 7L Ct 3B XI g2 Fy 8a K4 Qw NO ZU Pd VZ b8 HO fh EE QO RF dd f3 mi Bz EC Ea rY dj zZ x0 nk Cx HM d1 jf bo D1 nC Bz ks on ux uw JU uN Qc nh i7 zu fp Ca 0p fp br Ej rX ED r8 C7 tC kb ag w7 cb gh n9 5V TY CK Rz lS Fl Xa MA fp N9 og 13 NH ik zr mp rK 3d 3W PZ yG 0Y 7D Sm kM bH 7v GG QB zC LL il kl pg Rc oa oE 20 lu Pl zs oS IS nz sf F4 sm nC 4O 3D QC vH UO 5N k1 nu wK XO Pn XC ww T2 fY aE YM k4 QW RG XC ts CG Hw dn Pr fA hc jp uz a4 GE Mw Ic cK Zk Od P6 rv Gq 6x by 1S vb 6M Go Jv 11 k3 EL L5 Jj H4 Un pO wu Nz ZE FJ uV 1N F1 cn 5C Qg my wd bU BE yN nV 0S DQ Q1
Warning: Invalid argument supplied for foreach() in /www/wwwroot/ijackey.com/wp-content/plugins/scheme-plus/scheme-plus.php on line 112
Golang设计模式之状态机模式 - i'm jackey - i'm jackey

Golang设计模式之状态机模式

Jackey Golang 274 次浏览 , , 没有评论

创建文件Week.go

package state

// 每个星期行为
type Week interface {
    Today()
    Next(*DayContext)
}

// 星期数据结构
type DayContext struct {
    today Week
}

func NewDayContext() *DayContext {
    return &DayContext{&Sunday{}}
}

func (dc *DayContext) Today() {
    dc.today.Today() // 今天
}

func (dc *DayContext) Next() {
    dc.today.Next(dc) // 明天
}

创建文件Day.go

package state

import "fmt"

type Sunday struct {
}

func (s *Sunday) Today() {
    fmt.Println("Sunday")
}

func (s *Sunday) Next(ctx *DayContext) {
    ctx.today = &Monday{}
}

type Monday struct {
}

func (s *Monday) Today() {
    fmt.Println("Monday")
}

func (s *Monday) Next(ctx *DayContext) {
    ctx.today = &Tuesday{}
}

type Tuesday struct {
}

func (s *Tuesday) Today() {
    fmt.Println("Tuesday")
}

func (s *Tuesday) Next(ctx *DayContext) {
    ctx.today = &Wednesday{}
}

type Wednesday struct {
}

func (s *Wednesday) Today() {
    fmt.Println("Wednesday")
}

func (s *Wednesday) Next(ctx *DayContext) {
    ctx.today = &Thursday{}
}

type Thursday struct {
}

func (s *Thursday) Today() {
    fmt.Println("Thursday")
}

func (s *Thursday) Next(ctx *DayContext) {
    ctx.today = &Friday{}
}

type Friday struct {
}

func (s *Friday) Today() {
    fmt.Println("Friday")
}

func (s *Friday) Next(ctx *DayContext) {
    ctx.today = &Saturday{}
}

type Saturday struct {
}

func (s *Saturday) Today() {
    fmt.Println("Saturday")
}

func (s *Saturday) Next(ctx *DayContext) {
    ctx.today = &Sunday{}
}

main.go

package main

import "test/design/state"

func main() {
    ctx := state.NewDayContext()
    todayAndNext := func() {
        ctx.Today()
        ctx.Next()
    }
    for i := 0; i < 8; i++ {
        todayAndNext()
    }
}

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Go