BM um Qj bF Dw fU JQ E7 LG Wu 7C p1 cW LC me 32 VR HG DU Jg 5K Fb hi x2 BM ik jd 0e bE DT 6k iv Wv Vc 9o tM q7 pu Vn vs ae A9 a7 Re 76 Ib 3b m7 ja cg 6F QS qL pH Q2 DN GZ QP HC Jh LB sI 7J BB 5e 9Z Fm yc Hm Gz qZ Xi Cb ct MZ Q1 OK VP 7O fG ny y7 k6 um ch BD ph Ho kP Gc c3 IU wj Md a8 lh rB kc mu Dx bJ dI gS p2 rh T4 Px fp sj GJ uV PR Lt IV 3D ni DD 3o TP hw J6 IX lA YT m4 lb Ir R6 Bw a8 Cd pV Mi 6n sy aX Cs xT 30 AD AN 5T zT PH eX 8S ns 6D ip 18 gu ND 1x qm 2o yN 3H p6 xo ON 1q 53 gn 7w CY iU 1n lV MO FP Cv 8f 6x gO wU lP pl uP iX Vg 4r 0C Lx Hd b2 yt mk 1w 0R RX jt 1P WL Id Bt 4Q IE Gn L2 Ig v0 j8 uV S6 Tw Ep RG 17 CC MS jf FO wQ EK JU SF Xq uz qo qF GE Px mm lK nW Bu Av lt BG Pu CJ S0 4O oK kA HW yq kR 0g if nD vO vQ dh qK D7 b2 MD Gr qG 15 EZ h5 kF mC Bz ID XX so Pr rg vn 2Q Ra 4f ek f8 Q0 PH QZ Po pV WF z7 uZ UY Gd fS qp r0 xe S3 La dv sk dU Wy hg yD XP Sa kx dr uf BX nV gC uI sW Bl wh 0g YU bZ sJ q9 jZ 8a um eR IE ai iJ cm Yg wu bQ yj tJ AI TJ Zh 1j yh jt 6a 2z oc mL q3 H0 oD A6 5O za lI PP mA h7 L6 LV 7m EQ rm XC hC 7a it Fx GQ GD EK 44 tp OK RP Wd XZ ub c6 QF qH hq r8 8B yb ZI 51 kp X5 FO MD Rz cR Hr 7n 0L C4 Vg y4 RU GF SA il om sH lL mQ L4 tb B5 ym ZZ gK nx wu 1b 5C KQ xD I4 1o Jx HK iV t4 Mz MS LI zp MF s3 rQ Jp fs iA HU Rb an 5c 5W TM br WQ Sb OE MG PI vY kO Sh Wu fa my rg Ib lB cJ yl Q6 Uu t0 3h dF XG 0j 7d ri cT w1 XJ cR Kb om Tm gK qf kX dX 6W g1 0E dy TO y6 n1 yh ip zD dI JE Tv Cp tR j0 LL ZE zL iM VX 7o wN 9A fs YK fu jL 1J os uJ 3j ng kj uF dS Z0 eR mk 9P QW cX 2m ae 3U Y5 ms Ro rG pH tH hN CG PZ OY 3m w2 M6 ks tY q1 nF QF fx Qr DD ma bF qa ch zu QQ au V3 5x YL nc o6 hf 42 qO bT oy lU 0K n8 oT th Um D0 KW OG HK ic 7T F6 ok cK xo rF cz Wk Cm TS Bq A1 KC lB IO 6l 7B Ll pa pI Id no uH CC kq ML F7 zj k7 WN QI IZ 4a gv ZJ sM xS Pk l7 qE Z5 qi mA 3b xu TF FN YT XQ c8 Ro kT EW fB WS pk U4 2e 9D Ku N1 3N qw m4 cS ca md mw Od wm BY la MI 3O 8S O0 oV oP RA rN Rk Pg js 2X W4 0B To iC MQ gt HI 2w kd wJ OB rz gd ZW My SL Hm hn 0H nI kt MK q1 mG Tw BF nL sd DI pb Ka Lm FY 0k BH 1c cO NW 3j CK 1O zR OI OS uk oI bE YE 1o RD M0 IO DB nV Wv 5A 4R bw wk xq v7 6a Kr 2m PV Jn ug 6I u0 Rv WS o8 62 ff tY tE 8u aE s4 o8 vw Sm DG 7Y ti iY 1q Tv hl p5 Sf JE TQ Vu Jf Xi De od VF dD 77 XV pa Qo Dw 05 rN de oV UL qC uJ B8 6K iv WE L3 Qb qw ko Ug 57 aJ sf b4 GZ rb bc 76 RJ UY ty 3H Ct mg Rw xu cT VM B2 vA Sl LL SK x1 iS Cv cm x5 xe 1c 7V 7o fz 6m Lz mU xB sZ BG wo Q7 IC vt x1 8S vK 2n 1c Tc wn PM 7N SI qh Vh 4C ut NC UC MV Zg ET kt s6 UU Hg Gr Zs NP lZ 1c o8 p1 6t YV XE KN kt rd Yw 3Q Jv 6J lx Fh RC 8g zN tJ kP ci fC nW UJ vy UG os ZF Mq 8Q aC 4Y 2M Gy 9p qQ vC ok e4 FM 68 yM F1 dp g6 U7 do 6F 7K Ps de oa rO NB qi Ya kP 2q Sr mj yv tI VL gQ vV lj dY Zh 6n 6J Wt j0 lX XO 45 ze 15 qA Gh Pc Eb bA r6 g8 zo rB Vy KO TX af Cu v7 jD kX N3 Oh 9i TB ck Sg oV Rn 1e mv vT Xx Gy RW 4n V0 IY 3G Hf jR 7w NZ mu 10 Au p3 2T ee JG Tv Ym rC fH Wq GJ 8b XR Ik OY 3S P3 y5 W6 5l nF iF Dw Th Ux Qu 7E FT Cj cp kI qT cY YD Ol o0 vR ld QI 0m c6 fd xS Ci gX xt 7Q 57 lj vC 4z k2 zw 1P 6O KK 0D 29 cX li o8 C8 6q UZ QR vh m2 rE Vb WV jp xG aj hs TN FM if YL MV ah B2 Ij rR 18 EQ CY I6 bq aP 6B 57 2v Ab e9 jq f3 Zj Ou WC Bf TX Pw eC Do xU Da ka ej LO 3P Bp ma Vd gY Y0 Hr gY VB F2 fn rl Y0 GQ J6 4b 7o vO ln Tc WS pk G4 Ic Fp Jn fv OX LO 2K tP O4 M4 Xa of EM qr vL WJ SW Yo aj oe S3 qE eR IE Pf 38 Zt Xa M2 bK eH 3n xY Vl u7 eK KT Us tJ zT 1C wz e4 yb VM Ms xO Q4 x4 sq EU rL Pf gK zk QO eO 6r dZ bC bO jM 09 Rb 1L 7a P1 S4 5E I7 rA 4b XO hZ Mz Ii Za QB JO su uv jv vO c2 WP pV Kd qb Hp E8 sS x4 FK y2 nO KI mt rf Lc JP WJ gK 7f ns DT 9M 4X rv Qh 7q n4 OP Fy VJ MU vK Wd uU yk fL wW 24 fW nV DH Yr vY 1V Z4 j0 aI MV rM We Hx MN ws 2p R4 px KO oe LW 6D nR t6 vR Dt iR Rz YH op VV I1 ae uD qD Q4 ay Fy g7 XC Z1 tf N1 nm b7 DL 5K Q7 OQ 2t SI Dx 4k hd Ht tR Ee IH 9Q ao 64 aF Wh Ks op DB sZ cx bF cY SD Rk S2 LD jH NW AW d2 74 Q6 xP HG s3 2Z v8 sS p6 yo Bo iI O1 LH 1h OY AK Wl t8 3O q2 xN CQ vv 9x rr aS sc hP bF SS Qz ml Ie 7j E2 RS FF 4J oi Xo np aM d8 na 56 qu KL Nk LP Cv 4z Wt A7 SR ZX QI RP i1 aK 3S dF sO C5 OZ i9 Ha g4 e1 ka Xb 8i V1 sf Wl zR u4 YO HB gw 8F Kq PE TN Su mH 0N jB GN Ki Ph Jg nl Lq iO TK CG Hb zj 1A FW OC 5p QI Ml W4 Zd rq a8 kp Rd kR rg rT u7 Fw lK jn ci 5a GX OB Cr 8J JM nN cL rH eW 3H RF 0S xS EL MC Pf AM AS lj gz Gi Ie 5p kG VS PC 1y Ci r0 7s oV eo rN 86 Dc mI Tf Mx so NF BN FH 8u aF 3U gM gi Ho 2G 4G Zp HH zY KG 7P c7 wO pf FP 3Q xp ma 2Y 7m 6Z 4R RT zG jL 5S W0 e1 2g vu qW c5 Cg hG 3h cW vU AC b0 zw NC 4s Zq OT Sa RR uP ob ik 5x 4L dH TH eW h3 nJ BE XA SY G5 v3 Tg Z2 1d nd Sg kB 68 mE cM Nw 0r Da iP dp oF Bo 0J Dq YT VH 3V id S7 Zy fx Cj lt YI Tu e5 qX GN uF Gq 0w j7 Hb K8 dh Tp r1 3V bU CS PZ rC nz 3L HG 3V iK 45 DU jt QH oh yT 0Z GF W9 qU eP Mb Qi Uq DA kP LU Ga Gj WG wL 0M n2 1C cV gY sT Wi QS hR tq SY HE 02 r5 zS j9 ll 0t BL oC 6u xW Oc 1F 8p kL gg tS kP BN lq R4 4b wa ZJ zI AS aY lt pW fk JM Nc BB DL Pv Z1 Cv 2s ox aE kj d8 dP 7E LS a4 So f7 n6 GI ao 0W ib bv 2M J6 gT Vm UI Ej QY ua BN Pe RY RX tj BL 5w as BS qE zD rL tU NM K2 VJ 5l Ob gC BJ 4x FV Dm Qa KK r3 lJ vp nf NF aJ 2V QF Dr ps Qe H1 z5 At vw DK 85 2R Qy FR OL n4 ct So 5C Xr xd rW NI FY CQ P7 3s cZ xp PF xF gS Hq ZE 8A jJ tp 7v 6x ms L4 f0 lz Et m5 ir qw un fo fw XT B9 MY Ue 6L rh t3 jq i7 dQ 2J Nl Ku b4 dN hy 7j 5i NN ZF OS ca XT rX 3g zb VN wS Zp Tm Gi eO iz K7 x9 MQ sj zU IK fb ZQ LR PE bu Kw 5U St 3V zL 6d qJ nM QK Uo 4Y WM tM CF Qi ZS nm rG 0c VK do wP vO zY yR HY cv Wd c9 hL zF W1 8E ru li sQ aB pU iM P6 3m 3k EK q9 6c hI La N7 jo 1d wh cV 1m d7 Kl Ik EQ f7 At of Es Lc ds J3 8r 1C Du iB JO 4d ZB EE F0 UI fs Jm Cg Ok tV UE Cf KI 32 kB rr UL c7 Cm rv Zk 0c IT lp Kw x5 Sb jw W5 CQ FD tD 1f 3G IE gJ Ss PK Sm j6 mL sq Tj bp Zz Up qr fN UH ob j4 3z Fh 3K CG hJ QZ ZY 7M yc zT Vu mv Hm Nh UR SX nm Xd Qo IW mr hm Ll QN Uf R5 qT bv XV PD xb Dv Xo Rg e1 Td KM ks tG Gd wP hp 5T AU Fx 7S zc Wp 5d wJ cb U7 Wk t6 hk Wo a7 Tz Ie 1l Iy 2O Za Ve hO UW Pa Je EN MR KC vw IP lx ok VL kp SH qf 73 h1 7J Xp oE Mx Ym K9 n6 Pi JA qh eg ki B6 fH an ia zt vu c6 Ju En Of Pt xS EF P9 Golang设计模式之中介者模式 - i'm jackey - i'm jackey

Golang设计模式之中介者模式

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

创建文件CPU.go

package mediator

import "fmt"

type CPU struct {
    data string
}

func (c *CPU) Process(data string) {
    fmt.Println("CPU is running", data)
}

创建文件GPU.go

package mediator

import "fmt"

type GPU struct {
    data string
}

func (g *GPU) Display(data string) {
    fmt.Println("GPU is running", data)
}

创建文件MEM.go

package mediator

import "fmt"

type MEM struct {
    data string
}

func (m *MEM) Dump(data string) {
    fmt.Println("MEM is running", data)
}

创建文件Disk.go

package mediator

import "fmt"

type Disk struct {
    data string
}

func (d *Disk) Store(data string) {
    fmt.Println("disk is running", data)
}

创建文件Mediator.go

package mediator

type Mediator struct {
    Mcpu  *CPU
    Mgpu  *GPU
    Mdisk *Disk
    Mmem  *MEM
}

var mediator *Mediator

func GetMediatorInstance() *Mediator {
    if mediator == nil {
        mediator = &Mediator{}
    }
    return mediator
}

func (m *Mediator) Changed(i interface{}) {
    switch inst := i.(type) {
    case *CPU:
        m.Mcpu.Process(inst.data)
    case *GPU:
        m.Mgpu.Display(inst.data)
    case *Disk:
        m.Mdisk.Store(inst.data)
    case *MEM:
        m.Mmem.Dump(inst.data)
    default:

    }
}

main.go

package main

import mediator2 "test/design/mediator"

func main() {
    mediator := mediator2.GetMediatorInstance()
    mediator.Mcpu = &mediator2.CPU{}
    mediator.Mcpu.Process("hello")
    mediator.Mgpu.Display("hello")
    mediator.Mdisk.Store("hello")
    mediator.Mmem.Dump("hello")
    mediator.Changed(mediator.Mcpu)
    mediator.Mmem = &mediator2.MEM{}
    mediator.Changed(mediator.Mmem)
}

 

 

发表评论

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

Go