裝飾者模式缺點(diǎn)(裝飾者模式j(luò)s)

發(fā)布時(shí)間:2024-02-27
本文主要介紹裝飾者模式的缺點(diǎn)(裝飾者模式j(luò)s),下面一起看看裝飾者模式的缺點(diǎn)(裝飾者模式j(luò)s)相關(guān)資訊。
裝飾器模式檢查裝飾器循環(huán)過度設(shè)計(jì)更加復(fù)雜。
公共抽象類shape { public virtual string as string= string。空的;}類circ:形狀{ float riduspublic circel(float rid us){ this . rid us = rid us;}公共覆蓋字符串a(chǎn)s string{ return $ circle riduse cho 0-@ . com { rid us } } public void r:形狀{浮邊;公共廣場(浮動(dòng)邊){ sid: {邊} } }公共抽象類shape decorator : shape { protected internal readonly list type types = new;內(nèi)部形狀形狀;public shape decorator(shape shape){ shape = shape;if(shape is shape decorator sd){ types。add range(sd . types);} } }公共抽象類shapedecoratortself,tcycl: shapecodor其中tcycles :shaprdecoratorcyclepolicy,new{ protected readonly tcycles cycles = new tcycl: base(shape){ if(循環(huán)。typeadditionallowed(type of(tself),types)) { types。add(type of(tself));} } } public class shapedecotatorwithpolicy t :shapecodiortort,throwoncypolicy { public shapedecotatorwithpolicy(shap: base(shape){ } } public class colored shape//: shaped economic colored shape,throwoncypolicy//不允許相同的: shaped economic colored shape,absorbcyclicity//允許sam: shaped totor帶有警用顏色shape { private readonly string color;public coloredshape(shape shape,string color): base(shape){ this。形狀=形狀;this.color = color} public override string as string{ var sb = new stringbuilder($ {形狀。asstring} );如果(循環(huán)。applicationallowed(類型[0],類型。跳過(1)。tolist)某人。追加($ 具有顏色{ color } );歸還某人。tostring;} }公共類透明:形狀{ shape shape浮動(dòng)百分比;公共透明(形狀形狀,浮動(dòng)百分比age){ this . shape = shape;this.percentage = _ percentage}公共覆蓋字符串a(chǎn)s string{ return $ {形狀。asstring} transparent : { percentage * 100.0 } % } }公共抽象類shaprdecoratorcyclepolicy {公共抽象bool type additionallowed(type type,ili sttype allttype);public abstract bool application allowed(type type,ilist type allttype);}公共類cycesallowedpolicy : shaprdecoratorcyclepolicy { public override bool application allowed(type type,ilist type allttype){ return true;} public override bool typeadditionallowed(type type,ilist type allttype){ return true;} } public class throwoncycpolicy : shaprdecoratorcyclepolicy { public bool handler(type type,ilisttype allttype) { if (allttype。contains(type))拋出新的invalidoperationexception($ 檢測到循環(huán)!類型為錯(cuò)誤,{type。全名} );返回true} public override bool application allowed(type type,ilist type allttype){ return handler(type,allttype);}公開結(jié)束ride bool typeadditionallowed(type type,ilist type allttype){ return handler(type,allttype);} } public class absorbcyclepolicy : shaprdecoratorcyclepolicy { public override bool application allowed(type type,ilisttype allttype) { return!allttype。包含(類型);} public override bool typeadditionallowed(type type,ilist type allttype){ return true;} }類程序{ static void main(string[]args){ square sq = new square(1.23 f);控制臺(tái)。writeline(sq。asstring);colored shape color shape = new colored shape(sq, 黑色 );color shape = new colored shape(color shape, 紅色 );控制臺(tái)。writeline(colorshape。asstring);} }
標(biāo)簽:
不允許復(fù)雜性
了解更多裝飾者模式的缺點(diǎn)(裝飾者模式j(luò)s)相關(guān)內(nèi)容請關(guān)注本站點(diǎn)。
上一個(gè):這是一份茶人必備的養(yǎng)生清單,請收好!
下一個(gè):蘋果電腦分盤后怎么切換方式,F(xiàn)usion drive 被分成兩個(gè)盤了怎么再弄回一個(gè)盤Mac OS X 討論區(qū)

什么是智能配電網(wǎng)?智能配電網(wǎng)的作用和功能特點(diǎn)
wim10管理員以阻止你運(yùn)行次應(yīng)用(管理員已阻止你運(yùn)行此應(yīng)用 win10)
3D打印鏡頭技術(shù)可以制造檢測疾病的iPhone顯微鏡
手游人氣排行榜前十名(手游人氣)
諾基亞e7內(nèi)存卡怎么樣,諾基亞E7用著怎么樣
蘋果6plus雙4g怎么回事,ipone6plus雙4g版手機(jī)是什么意思
混凝土空心砌塊墻體裂縫的防治要點(diǎn)有哪些?
無線傳輸數(shù)顯扭矩扳手,無線傳輸?shù)臄?shù)字顯示扭矩扳手
對方不準(zhǔn)探視子女該怎么辦
交通事故責(zé)任認(rèn)定原則和劃分標(biāo)準(zhǔn)有哪些?
十八禁 网站在线观看免费视频_2020av天堂网_一 级 黄 色 片免费网站_绝顶高潮合集Videos