package Ġcom . sol are x soft . design patterns . pattern . behavior al . strategy Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġhour uh ou Ġon Ġ 2 0 1 9 / 9 / 2 0 . Ċ Ġ* ĠDesc : Ċ Ġ*/ Ċ interface ĠProm otion Strategy Ġ{ ĊĠĠĠ Ġfun Ġdo Promotion ( price : ĠFloat ): ĠFloat Ċ } Ċ Ċ class ĠLi J ian Promotion Strategy Ġ: ĠProm otion Strategy Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġdo Promotion ( price : ĠFloat ): ĠFloat Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( price Ġ> Ġ 5 0 ) Ġprice Ġ- Ġ 2 0 . 0 f Ġelse Ġprice ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠDiscount Promotion Strategy Ġ: ĠProm otion Strategy Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġdo Promotion ( price : ĠFloat ): ĠFloat Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( price Ġ> Ġ 1 0 0 ) Ġprice Ġ* Ġ 0 . 8 f Ġelse Ġprice ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠProm otion Activity ( var Ġoriginal Price : ĠFloat , Ġvar Ġpromotion Strategy : ĠProm otion Strategy ) Ġ{ ĊĠĠĠ Ġfun Ġget Price (): Float Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġpromotion Strategy . do Promotion ( original Price ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠEmpty Promotion Strategy Ġ: ĠProm otion Strategy Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġdo Promotion ( price : ĠFloat ): ĠFloat Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġprice ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠProm otion Strategy Factory Ġprivate Ġconstructor () Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠP ROM OT ION _ STR ATE GY _ MAP Ġ= Ġmutable Map Of < String , ĠProm otion Strategy >() ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠNON _ PO MOT ION Ġ= ĠEmpty Promotion Strategy () ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠLI J IAN Ġ= Ġ" li jian " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠDIS COUNT Ġ= Ġ" discount " ĊĠĠĠĠĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠP ROM OT ION _ STR ATE GY _ MAP [ LI J IAN ] Ġ= ĠLi J ian Promotion Strategy () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠP ROM OT ION _ STR ATE GY _ MAP [ DIS COUNT ] Ġ= ĠDiscount Promotion Strategy () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfun Ġget Promotion Strategy ( key : ĠString ): ĠProm otion Strategy Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠP ROM OT ION _ STR ATE GY _ MAP [ key ] Ġ?: ĠNON _ PO MOT ION ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun Ġmain () Ġ{ ĊĠĠĠ Ġval Ġactivity 6 1 8 Ġ= ĠProm otion Activity ( 8 0 0 f , ĠDiscount Promotion Strategy ()) ĊĠĠĠ Ġprintln ( activity 6 1 8 . get Price ()) ĊĠĠĠ Ġactivity 6 1 8 . original Price Ġ= Ġ 5 0 0 f ĊĠĠĠ Ġactivity 6 1 8 . promotion Strategy Ġ= ĠLi J ian Promotion Strategy () ĊĠĠĠ Ġprintln ( activity 6 1 8 . get Price ()) ĊĊĠĠĠ Ġval Ġactivity 1 1 1 1 Ġ= ĠProm otion Activity ( 1 2 0 f , ĠLi J ian Promotion Strategy ()) ĊĠĠĠ Ġprintln ( activity 1 1 1 1 . get Price ()) ĊĊĠĠĠ Ġval Ġactivity 1 0 1 Ġ= ĠProm otion Activity ( 1 0 0 0 f , ĠProm otion Strategy Factory . get Promotion Strategy ( Promotion Strategy Factory . DIS COUNT )) ĊĠĠĠ Ġprintln ( activity 1 0 1 . get Price ()) Ċ } Ċ Ċ // ĠComparator Ċ