Decorator pattern , head first -
i reading head first design pattern book , decorator section. can not understand 1 part of book :
"wouldn’t easy client of beverage end decorator isn’t outermost decorator? if had darkroast mocha, soy, , whip, easy write code somehow ended reference soy instead of whip, means not include whip in order."
any body can me understand main topic of section ? problem head first mentioned ?
i think wanted point out, fact can references mixed if not careful , how create decorated objects. consider example on page 98 (first edition 2004).
beverage beverage3 = new houseblend(); beverage3 = new soy(beverage3); beverage3 = new mocha(beverage3); beverage3 = new whip(beverage3);
if stuff in between steps of creation, might end mocha without whip.
and wrote in answer section:
however, decorators typically created using other patterns factory , builder.
if automate object creation, might prevent making reference errors.
Comments
Post a Comment