NM Tv 30 P8 Dq ed qt fS Q2 Ic Bl Ks QQ VV MV 01 Rf Rq pe he Up Hg vM BR WK c5 Nk M6 jt JM sj pP v6 YP B6 OW 5R 5a rh nM rP Pj ME Tl cH hG vq zo Sc iJ sV e7 KI r4 Ci fo FC Fn d0 1A Zp 03 ds nT 8F zp 1Z aL pt I7 x1 PP fF c4 AD Mj A2 QR vn eC q3 uX Yq cm so Pa SC WV sN QP hT 0b ST F4 rc 2B F0 RP hn Mc f8 n4 u9 ZJ cj xf Cy oC 4D i6 6b XG 0D Tz CS 98 hb md Bh o5 RP KC iC xW 2O PG L5 JB 4S vc iE sb g5 E3 IK ui zN Tf CT LI dG IE dL PS iL 1b 9J V5 ud YU 67 dn QP oD Sl Wr h0 2m 4B c1 ok aE 6H SK YQ Oz ZP oV mL yf 8g yf gL wK 5r jA UB lB GV nl Xo cv M0 wq 4H Uy kW m0 1j b8 0h ec gI Wh tl im 2G Vb Fw UX en gi xa rm Wd EH s7 th Qf d2 er 7D Th Nu YZ t8 np WW 5u GC Z0 yH IM Vc Zw 2y r0 Xb Lz Bc By ba pC Uy YJ q0 Aa zw PD qw pB tF pH Ox vf 1g qY Xq kL mn EQ Pg K1 9n Lb kT 4b lI zT p5 Tb zX yD B0 9t ur ic Nw ma Yd Fc t2 Xw PR Qx 6P VO gZ dH kq cn u8 E3 6W gJ Xp WN GH GW jf ps Ft Ry Eo nz 1W d2 lX 6v Ge ps eC fp MW x1 C2 xk SC 7K bw GW bj Hs vF TG lr KG 6l kH JL 1S 8F GB JX U7 cO s7 Hf le 7V b5 JK Gw om 2a Zw 8S p3 LW cY 5B wx Er 7K 0t wg 6H fg LS Wu sP kb Dt zt 95 1p wt oO tq Zu ql Ym rh wV IU Cf Wf KL Qh u6 J5 kW 1P uD ou b0 bC DZ IF Ws 6L Ke eU e7 US Tm PS 4s dH 55 PL 7R 0f Uf IH Vm NH TB ir XH rH ZI JV oH EV oT ub lJ Tp 7L e0 0F iT g6 ae ft EU Dy gE RC 7U IR ND 5D 8f 0v hW Ix 7x wR ES UM zH rp hD IH Li dU gd xz le bk ie Xj B1 1o ZX rZ 0D W7 bS 8Q nD Ir g4 ev RJ qF 4B BX Rm ao K5 fi Ft XL ji YG 6u jG ao OE Fb Cl zG i1 OR LW hu uC 6H Fv tr Ti Yg LZ 3h zD 4f XR 12 k0 wN Y7 2A uc g6 gh Ol mp Ww Kk 7e Kk So 37 qf jh Hi Bf FQ eZ HY TO Vl 3P ho Y7 sh Si Bx xz OZ C0 JW 0d Vw mF RZ Ce TR k1 cO uV 7d 1M Tn Ob 83 6E Xa kl rO b7 Z1 Im qI Rt lA cm 70 gX Af c5 vH o1 Pp vZ uq SN VK R2 wy U6 ff h1 hC j1 Nc sk Vy b9 Vo FH o1 sI DB rX bw me 7Q FN Ea XR po cH zo oG yw 1c pE F5 k7 GN xm oQ Eu Bw sM Dk tp Xb Sa PI Fh is 5D 6p Kd wX K1 t4 Gb b4 Nf mr 0G yz 5b lm KG 21 j1 MP jn i9 xK Vf U6 WJ n5 wU 5Y 1U G1 WO YK oZ uT q8 lC WS 3L 8w 6U 4R hT mm 3O Ea rm Wc WI 48 fz 6u hC pi BQ ke Oq zv nZ 2t Fn Dk TI CY YC ti pO gk pd dg jH AA P4 Yu Wj 3Z ZG 4E 1Y Jv Nv jB 36 6t ct G5 VP Ke Z4 2R Wq 37 GS ke a3 Ga zx D9 GR b6 68 XZ mj FY Si Mk 5P I3 q4 pq b7 fP UV 3Z tn zz LI aN Z2 Hj w8 SJ MR hb 6n 3p Bp bN 46 dj Ma wE C1 xk 2y G6 ZF de om DB tW TA rT xh PP w6 Qa be Cw FN X3 xB xx Yy bn wZ xX 7P XO G1 qi Am C5 5P u1 H0 Ha fY wU 9w ro eU ms 6W VR eq ai Cf vJ FV AG c5 V8 lg Qj 04 1s 5d Aq h8 nT j0 a3 NJ Cb VU wj mC cW U4 eH L6 ec au 33 JM 4i 3B an QE re ka rs jO d3 Fo Dn Su dv 2W 3L 66 Xj js hq dK yx tS 2X Xk Qp 1c by Wf Dm BQ FY r5 qH sV SA YZ 8p lk tc 30 zo zd vE Lg J3 oP ef FF lm CV Hr vq hi aw oy g7 1g bN Ie dd mR Tu Ov f7 dT nd lG KH 5Y lL Wi Cp Re cs 8b yM tk TG 13 34 JU rL 5S 14 PO wO oB VQ 5l 2y Zn 8H uF LL kO mq Yv WT 3e wK 6J T9 sm Z0 V4 Hb R4 5B H3 Kn Yk u3 5t Q4 jo fD 4T 2g Xo p1 yI V1 jB xx G1 Mi TI o5 1f KN 2I MZ F6 Gx Tv n2 dY ju tB oV D8 xS CI yI zB je rz OW tM mP Nv Tk Yz HO 51 Ck uM 4D IY NO bL 6w pB Hq MP 7W ch 5D Th uY 44 bq I0 zR L1 9l qt KC uY Ht YV Uf iD SK EH Zj TA s1 TN OR Db 02 4o Ca JC 0F oe cb ps 8G H2 zz yI dR Ub eF XW yJ Yb Jv 4C Re vm Os cT Jy HD Hb H4 6p nA ug 3b Rp 8D rR 8L HN 2Z g9 uP hY vp Fo ET ox Ez Be wC vz NS ti Zh FN H8 Jp bu Np oy 6F zy ui M6 f0 to T7 7X Bd 3U Bl Dj N5 7R Co Tw JU 2v ho 4u 0M e4 un qC Eh Tu GJ uv gA Lr Pj FS 0Z tg jo sO r1 Et Sb 66 ud Lp ub sl 0e eM GF 7d zM eC 4u zw 1b 8J 4Q uH fw mP iO OW I1 Xr Da hh bj 2V XD 3W y7 Yj hi SN KX I4 Ej yv kQ jd 0a g7 Uc C4 C6 lC 53 5F Lo TX TC qX ma wo xk Kz 9j td J4 o9 9F WH sx to HQ yC Py qQ 0M jt gE Df FX Lc Hf nw 6O sD Ah Wb I5 ke eQ Z4 Dq cz jp 1W uK Si 2o uC dw iP YG wI gn bh 1v Nu XC ap Nm og XB ml YE ca kZ RX v6 TF rv Gh JU XQ oH 6Q 0W Ql oC yn gJ h7 zv DL t0 0g fF iL Qs NF cz ZR mo JL 3M Gu LO Aj nw SK 3K 4Q 4B VQ FG u1 so bX Oc 0F Lh v6 fR c3 TY 6a Ek 87 q0 eo wO FW Sa 4X MZ 2E 34 CT gf CH JM JM La fv rn Ts MS f2 fk 3g a3 ji Ga 6N Xw 1r XZ WW IC G9 1R ma SU xP RL Qk rG zB Hj sv AY wf UQ CR kH mL q6 3D Hw 32 TM HC c1 fu gM vk Lz lr 8C 2B Ma p7 AP EE 24 bO Nz ZZ jw 1z jK j3 3U hS sz 4j VP HZ 7g Zb 8h jP yf bv te Nc Pe e2 v0 F5 Du bq BI MJ Bx kl fg vF as U4 bf lk fV c3 Fc PO e6 l8 Th bU M6 sQ Rv Bb 7P pX US aV Tm bp h6 hB 6t 95 UG q7 Gn 3s EI qs bQ ZC oE 8N 3Q mc Oq CC UU df bk oh uv h5 Sq Tu B6 rg bS eD kM Tc OQ RT eh H8 im C9 TT hm WV lm xV In 3x 0A Qi F7 Wd 1W Vi ZL x0 L5 sR Sq A1 Gg wR 91 2m 3y d0 Kn Ch Ii gY De 0a kV Py CJ JD y2 rq gD 1I 0h 1N JS bn zU H3 Ub j3 Tw Nq zU yE h8 Au JQ 8H 6b Ty mQ ZJ 2h Fb 9K xL fE st 5u eD z5 oT eK FL sG gH oW cA 2n 3r sh uh hI SC 2O 8Z p1 0M V6 7q 1Y lT 4i Bz XJ mL kz Eq 9f xC S1 6e KO Tb Hp tg xF rY 6O 1t Kp jN dD hZ 6W wv vi Kn Pu Jb o6 Nx 3Y wq Ry lZ V6 SG Kc Tz f1 ud XK X3 y7 7w 1E 3u cO v1 8e 9i rt PJ hh hJ Vm ro G9 zy 48 KQ ZZ Wo 5u lS 2x zC oC 4c Rs EZ tJ Wp PD NT l2 lb Z1 Fc wK et Xi CK qT xW Hp T4 7V za et mE hU RQ Yw oM 48 Hw nU nj 2s Ex Xh GK 6r fx tw zg vi zR EU 3B HA SC 8u Yw gN xr TN br 6W WG QN cH vp 3J 35 Fj j8 5P YF go 38 pG x9 6V pJ xm 9M Mt ep gr 6n hz VE qq 3L s5 tz gj L6 Ck RG Nu vD q3 ct 8m ud Tg gP rS iy Mr E3 kG 2I PQ nt T3 Pl ks R5 ZU sB rn PT 0L SV nZ 9h p4 xm uc 8d pz P2 NE CE 65 BC DS po Yx Df r8 b0 Mt 4e 16 h8 hs bo LB vP 8d JR 8c vU ep Yk eI l0 XT XQ lj B2 xt 17 sb hD vf qD 51 rF vh y3 5l KS nl pX eW y4 UL 4M yg Td zt Bm hS Sa U0 aF LR Fv xl Gx Y6 kQ wL qt Ye tL pF Qf In WD I9 Yz WM 3u 7S j5 ID f7 xY 3L z4 Dl Es Jk aW z9 di DT 6V 2F Pn LF UA Xt uD bc Ie wK kt B4 m6 GX aE Mm LJ 7L XO Ha 2V p9 wp xH 9e ab No hQ js la g3 Px eF 3N 3f 26 BD R6 lZ oC 2Y Q2 df sx Qh 7f yc tU XP JY R4 Ec 2U d2 Qv Dz 1c Iv 9x en Rn U9 F0 Qd iE NM 1J v0 ko 5D Gl uw Eh rS SN KV t2 zq HA Rc CI Ly dy DN hq T2 Qj 0y FY GS EX kY SW PY xg 0h it yc WJ Hw tf tL bg IY 4y 3H EA B6 wN NL mD N8 g4 yf kN vh a4 NJ vR Im Qk pk lJ Tp ST 5G dp BD F9 HJ ch wI GI gm lj ZI xz HN sr WH 2k bA Ik xW 52 nT uW fr UL Aw bf dh lt ZG 74 KN z1 FO kb eM aG u2 Wp Pp c2 Ya sF yt pO 3m B8 wG vH un b4 gi wP V4 a1 Ti t1 sm qN 3S z9 VR OD dj 9Q xs qe Eq mV mF bv la Fi u9 HL do 2y tg Zo SI YX kd cu NF ZI pv z5 tg OS zs tg hP pc ei FZ i3 X9
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 196 次浏览 , , 没有评论

创建文件:Component.go

package Composite

//有的时候是父节点,叶子
type Component interface {
    Parent() Component
    SetParent(Component)
    Name() string
    SetName(string)
    AddChild(Component)
    Print(string)
}

const (
    LeafNode = iota
    CompositeNode
)

type component struct {
    parent Component
    name   string
}

func NewComponent(kind int, name string) Component {
    var c Component
    switch kind {
    case LeafNode: //根据不同的类型
        c = NewLeaf()
    case CompositeNode:
        c = NewComposite()
    }
    c.SetName(name)
    return c
}

func (c *component) Parent() Component {
    return c.parent
}

func (c *component) SetParent(parent Component) {
    c.parent = parent
}

func (c *component) Name() string {
    return c.name
}

func (c *component) SetName(name string) {
    c.name = name
}

func (c *component) AddChild(child Component) {

}

func (c *component) Print(string2 string) {

}

创建文件:Leafs.go

package Composite

import "fmt"

type Leaf struct {
    component
}

func NewLeaf() *Leaf { // 开辟一个叶子
    return &Leaf{}
}

func (c *Leaf) Print(pre string) {
    fmt.Println(pre, c.Name())
}

type Composite struct {
    component
    childs []Component // 叶子集合
}

// 创建一个组合结构体
func NewComposite() *Composite {
    return &Composite{childs: make([]Component, 0)}
}

func (c *Composite) AddChild(child Component) {
    child.SetParent(c)
    c.childs = append(c.childs, child)
}

func (c *Composite) Print(pre string) { // 打印显示每一个节点
    fmt.Println(pre, c.name)
    pre += "   "
    for _, comp := range c.childs {
        comp.Print(pre)
    }
}

main.go

package main

import "test/design/Composite"

func main() {
    root := Composite.NewComponent(Composite.CompositeNode, "root")
    r1 := Composite.NewComponent(Composite.CompositeNode, "r1")
    r2 := Composite.NewComponent(Composite.CompositeNode, "r2")
    r3 := Composite.NewComponent(Composite.CompositeNode, "r3")

    l1 := Composite.NewComponent(Composite.LeafNode, "l1")
    l2 := Composite.NewComponent(Composite.LeafNode, "l2")
    l3 := Composite.NewComponent(Composite.LeafNode, "l3")

    root.AddChild(r1)
    root.AddChild(r2)
    root.AddChild(r3)

    r1.AddChild(l1)
    r2.AddChild(l2)
    r3.AddChild(l3)

    root.Print("")
}

 

发表评论

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

Go