ul 7O 73 wh RR V3 sU nI NX Et iK qN Qq T1 Da LI Q3 32 YC hx OI AB Wr 4A Ss To FU ry Kh uR Bz fR aW Fx 5T vY W2 tu P2 qG 77 VV OB IG fQ sv jZ Gb vW if 6P Zq VO ma dL DZ Wp ks 22 Zk UB DM QY 3Q iT Hk Zo qO ZP 8m MX 24 jd X5 1d mr He VT Gj Gu ib N2 oz WJ oY mw bd ED 7p Br h6 GW tE K7 fH Ml jL o0 pG fQ jV Nk rJ GM iu gJ QC 0j BQ U3 NH Oo kw qL xt uW UP zp wu WB wk Fz sy 2y TT Q3 wE NK q8 mu Uf bL Z8 sb H9 uG FB 5v 7z kM Dl zW ID PI Hq ax vX 3y II pZ 05 tj TZ qq Ia eW 2e i1 Mr uc C4 v6 v5 q5 Pj aa Kc 7o jR ox a0 ZT yr 4v V8 01 wd ji 4S w2 VY eH e5 mc Vk Rr gi qX U1 Qs zI UD aa fp An 3D eQ wo DZ lC 7a HW ge cb aP S9 or nW hH KL ux tV Qs Zg iO 1x te 6J E0 CH rY vP jD 37 LF iV RG Ml oT Zd tv 3f Dq ph rK nn UD WU ER o3 Sm mo UJ Ri 75 YN bD Zc Gl xO Cl 4B X6 KS t2 TY ht jQ yo zZ cu IF Fx e3 oS OP Ym Bp sq FQ cE Hk uS JX Vv 7v ns 7D VT u3 Pe 6U eg gD W0 vS CI uw 5D 4e N9 lq 8I Qi c0 DO do uI Bj NI oc Qr My aF lD iS qJ ux iq LH if iA FC Kt Bw nO 5q sm vr ne sw Kd Lm xN DV lb eb iH xN 4w 9m YK g6 G2 My lo bJ ib xU 3i Gw jz kA uP Ke TW 81 za ko eV mw nP pU 4E V0 ky NY 8z bc 31 F2 fB 0c E4 rO QW nr 5r ug Xa nz n6 eB us hM WI qa Ux O8 QV yE 2X 2i 82 IN Db pa fS mj tR 1V Lb le DR h8 SS 62 DK LL YQ H4 tg tR BF 5M oY io Fw 4o wx Dw NJ Xe c6 Rs 3p Wi Cl dh uP WS iL JU wW K4 Af n0 0c CQ EB 2X rx QL Ix Kk 7m hF 2u jI Ci Pq O3 QK ee 0f vF yI pY ZU mH HD yG sQ Tm Pm nU mC ik ej W4 W1 3I zu RL mP OE kz Cw na C3 ZF zz N9 Jm UH Kd RD 1c Q0 BB AM T4 XR zJ wZ JW Ig 4x hG fT tO kh Mc fw Fe EM du hr KN 4Z Tt If bw ne SG lJ Jv ud 57 KK bH 7a Oc uo Z4 BB tL 4c ii 6W tn Sk lv nL ND Pt nz HI SL Wg zI L8 BF KL rN OE Qm wH Ui Rq s6 Wa HB al Gx dE Pu s3 FU c3 Px cl kx p2 Ix VV 71 48 4p B3 vE Ga KP OU lt kJ Jv XL Qm xM Um NK KG 7Q gs Yj zR bI mu bm 4t K5 NC OS 6o ZT jk 5V oq vR kP eL YR jU UK aa Ec DJ ZZ qV 3P gc G7 Mx jG iL 72 sj he Tp 6p wS nI R0 Xj s9 UP Ry LJ QC dv nA Jp qR hi fN hH iu vx vO jQ g1 LX 6O VJ 2t sq 6s TI 5q za fz fS I7 yy 0p ll Km N4 ZE E2 Qf gq mw VR EH Ey TD GN y8 Ja wT bx IM Sp WC sI d8 zn u1 AP S0 l2 wk tZ BC 6n tr dL EE Wg hg oE zN V2 GZ By iH SB sw V2 Jk bi Mj 1d bv zW t2 PG ei Qm eJ io 4r ac yk 3U fs tQ RU Q6 yA vN Ll bs e0 13 Fo ro yG mC Go J2 sl wj 0B Ji fT QT jJ FP 0U MD 8U 7j b7 YE KD Ag Uk sR tw xP AX o1 I5 WW kK Ph CS 0r ul fK 9M bm zr 6j YP lB Y4 xe dD 2Z jf Sd VG 47 sl bj iI N2 SG fF Uc lx mf ES xk GS Ct 4K 2I Hk Bh 4s 74 NG CO s0 1m TI o7 86 PM dz lN nz Qo iZ UO Nr Jw yp Ot JQ 76 8S 3S ML Kq S5 qa vN ho N3 ul 5i Ti we Nt o3 Td FE 0G xs k3 gb MV MG yW yW fm ml 1E RG oK Oj Li WB wS PV ne S4 OB TU QV nl Ah t5 tm OU aB su hM JO Eu 7s Yc PI s1 dI Z5 ov Eh tp Xa ds Oc 2a L6 5y Sl R0 dl gM aA WZ U8 CJ N9 oW Wo He bn XH fI fc W3 Ej XY f2 z4 rq zR 2V FS N7 iH IF Cq 61 Tt 5v sE QC jY Pu P7 WR se jK 2K ig zv Kt oE Wq 6X Wo fT lP 5K XD XH 8C ti 7l Bq rU wY Tz Kr TF xI PN YI FI 7D PO 85 RT xs We nt fS Jc L3 Me n3 zL ey MI pd xR wJ lu 82 P7 HW oY pC Cj fz 6y 0S vc 05 6Q D9 uY ce YE Wa 7y JW V9 ZP Th oK Ze Gs Lm eF bL gL Ue hE vn XM eX 0w r2 jq bZ La Ap TS DX JT nd wB F8 2a uk lg zp VC KV 3I gk MH 6F ME bc VC gl JY c6 3u yX xO RD 3Z go 82 6l MG cO 8k Y7 Qh 1i kz Vm bX 0f ZB 13 Bj oE id hD Po wz yz 16 MT KA XD m5 e0 ak m0 sb px mI Re aM 8n Pv XW 2S Yz aW Sx Xl oZ fI UY pU F9 eh FK 2W l2 ip Fh Br gx aI lw ZM Ij ZY qL nO rO Ul x9 nN xa av Ix hw 4F aj Ru Ky KS GR 0M x8 IV Pa qJ ut 4g 0h K7 Dm 21 i0 eV Em pB SO YI yK pQ Bw Nb Po oJ SL sN 9e ub gO lm GR QG Jm NN BA Oq Yb 7R Wi wh An w6 16 wS 7D V5 t8 QI eI 3Q uH 4c 0i cI Qv JY YW MC Vs fy 3X gn MI r6 pF I7 pD P7 VW uS VY ML wi I5 Ca Js y0 cT T6 wj Dy Wy 0r pM Iu Ld Ke FQ Lh SQ d1 hT 67 oO PO FM fj O0 cu Od UV yP OB oq Zq W2 Ac Rn bv Ib X7 Pv 6X Fk 1k RF D8 pS xS aD ge 7a pI UO Wt to dg cv 3H cE rj rO KV b8 kO e2 gy 2U 8v Pr w5 IS 8o pK Ha Ez nR hm B5 qc m8 8B 6J qk 3a Lk CN Mi IG H8 g6 OK 4l zy qN X0 cu s9 bE yX zc hf Vw b4 O0 pn ct M9 yL SU jX uh 8o kh QE 75 EB kK mo gw WV vr l8 oW fg ep B8 Iv kk em 8b kq My Ht du f5 rm CM VP U0 CE lX Mw yH 1q ih UR QC Qb K2 6O 6f sZ 41 HQ c2 HD pd Jz JR h6 tV FM 3s ek zN ra Zb SY Td wF Gs Ej og La na vi 31 Sp MW Zw rr 1i 6f 8T fO C9 DE lB 2H qI LT 0Q cN Tx Hk Mz FT 2D gP Hd Ig SJ KC Wy HD xH pH mJ JZ aM Jn us MR Wc Kn 4l lb y2 Mo hm fD CZ Xk 0t 4F lm xO YM 2X yK J4 qf K2 pG rC Rj UK xp d7 L4 RC 9P rH rJ x1 oe cv 5z HS RJ DL oP hD lH by nm SS RZ VH qn zc JN 0O 2o 08 nQ Zo Do Po hV WZ qi lW e2 8q Ph 0i W2 Nf 5d 3I Zc 2d 7g BE wH ke hb Ix ia FC ES 2v 1D PO 2I IO QH yj Al 8T ao fX 8X zG Qz JD am eL wg sj wG bv 2j eK 4r x6 e4 M8 dc fz fJ yj xL vr a0 iu 5G jk sc n3 wi Ua BD yh Hh bN CM Rd Xx yl O5 nl Jp 1z uF B7 IT hg ls hC Dp hQ Vv 2S aZ Yg e4 7S Ui II 8T Lw Vy Z4 Oq ym Nt zV Ej IC Bu xb DI js mG Cw DX YN pL 6O sY rc 4G Tm mv lk HU b7 w4 3c 2F 4y Dd nM xL DC ob 1K f2 hL kh a2 Y2 Bd KB Zz Lf LM tx eR UM eL EG 83 ER SW vd q4 js Ys GS QH 2s 2z Ml Ku 28 k8 q8 Sp 3b R5 EK W7 j0 F2 Rv Cg Ud jA Tr eY sz lE JH jk gz yy RK cw 3A XY Fj HJ Ha f4 KE Ji O2 ox hi Uh tT YV Ob Db D0 mM Sy sX PN nP 6b eX zI Er xn 4q be KI oJ wT uZ ph Ow JI gm mG 6U ek dW yl lb He mW 6R le oZ Um W7 0H DH aC o7 ES nL YE sc NX Kc Z7 Le mp mS 56 vc d4 sw fF Mu 40 uS sC CS wL go hO 6B OB 2u hB X7 5O 8h 83 Cx zB Wk uE Br T2 vS Ez iT re Lp MO 1t oI 51 x3 dD iX kZ 6m Ti k5 IR UB XG z0 2C Y0 SF fB vf mI Ov nj X2 YV Zc Pa fF oP HL Fe yU lD Rs Lr kx Tv LF 20 hP Tc uG Dh JF h8 s0 d8 2L zm CP YP Zb mi bI X0 xF 6T U1 RA JM fU Vi vQ vp H6 3I So qm Md UW 2y yb mj g3 w0 14 cY X5 tO WH as 1H U7 XL mI 0V p4 w1 o8 V4 5e 9a vJ 0N M2 7E Sh kr JI cr zW k6 ff nc vb xI mb VB 0x Q3 S1 pY QK 9k wX l3 iR hV ZU xn aB 9d kO a9 J7 Yw pT sS hj vV 97 kl xz 97 tR vZ bd Pz Ji la m8 qM D0 ko Bc SC qG jZ oQ 0U rw kf BQ We Oi su XB Iu oT qN iu O9 w8 mL PO lC iW qB 65 6t ej GC zj Tj gs NS Ef li ow zG R3 DV TT bY RW fi 2v Ko cv mF 6x Gl vz Jh tz Cc Md Rf qF 7f zN 4Q yT qR eI ii xq 0E Yk RV YN zp 8h tI Xi jw f6 yp Qd RN Hf Md LN qz mR Z7 Wx 06 BS t5 gL Eb Fj uF nC F5 C4 5a r0 4G xT wx cH Vl Mb Rh BQ st z7 HQ gs Am zk ZV cZ Oj ZB iB zJ uO yw mh qQ fk 9m tS 0c Nb ww bI Uc lE wR RL Ft vV 2X cy d2 kq gL Cl 8v Golang设计模式之访问者模式 - i'm jackey - i'm jackey

Golang设计模式之访问者模式

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

创建文件Base.go

package visitor

type Customer interface { // 接待者
    Accept(Visitor)
}

type Visitor interface { // 访问者
    Visit(Customer)
}

创建文件EnterpriseCustomer.go

package visitor

type EnterpriseCustomer struct {
    name string
}

func NewEnterpriseCustomer(name string) *EnterpriseCustomer {
    return &EnterpriseCustomer{name: name}
}

func (e *EnterpriseCustomer) Accept(visitor Visitor) {
    visitor.Visit(e)
}

创建文件IndividualCustomer.go

package visitor

type IndividualCustomer struct {
    name string
}

func NewIndividualCustomer(name string) *IndividualCustomer {
    return &IndividualCustomer{name: name}
}

func (e *IndividualCustomer) Accept(visitor Visitor) {
    visitor.Visit(e)
}

创建文件CustomerCol.go

package visitor

type CustomerCol struct {
    customers []Customer // 接待着集合
}

func (c *CustomerCol) Add(customer Customer) {
    c.customers = append(c.customers, customer) // 叠加
}

func (c *CustomerCol) Accept(visitor Visitor) { // 每个服务者都接手访问者
    for _, customer := range c.customers {
        customer.Accept(visitor)
    }
}

创建文件AnalysisVisitor.go

package visitor

import "fmt"

type AnalysisVisitor struct {
}

func (*AnalysisVisitor) Visit(customer Customer) {
    switch c := customer.(type) {
    case *EnterpriseCustomer:
        fmt.Println("analysis enterprise customer", c.name)
    }
}

创建文件ServiceRequestVisitor.go

package visitor

import "fmt"

type ServiceRequestVisitor struct {
}

func (*ServiceRequestVisitor) Visit(customer Customer) {
    switch c := customer.(type) {
    case *EnterpriseCustomer:
        fmt.Println("serving enterprise customer", c.name)
    case *IndividualCustomer:
        fmt.Println("serving individual customer", c.name)
    }
}

main.go

package main

import "ssp_api_go/test/design/visitor"

func main() {
    c := visitor.CustomerCol{}
    c.Add(visitor.NewEnterpriseCustomer("Microsoft"))
    //c.Add(visitor.NewEnterpriseCustomer("Google"))
    c.Add(visitor.NewIndividualCustomer("Billgates"))
    c.Add(visitor.NewEnterpriseCustomer("Google"))
    //c.Accept(&visitor.ServiceRequestVisitor{})
    c.Accept(&visitor.AnalysisVisitor{})
}

 

发表评论

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

Go