Looking for Основи розробки програмного забезпечення на платформі Microsoft.NET test answers and solutions? Browse our comprehensive collection of verified answers for Основи розробки програмного забезпечення на платформі Microsoft.NET at do.ipo.kpi.ua.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
public class ValidationProxy : ICommand
{
private readonly ICommand _real;
public ValidationProxy(ICommand c)=>_real=c;
public void Execute(Order o)
{
if(!o.IsValid()) throw new Exception("bad");
_real.Execute(o);
}
}
Що тут Proxy, а не Adapter?
Перелічені патерни відносять до
Агрегація
List]]>x = new(){ 2,4,8,16,32 };
var agg = x.Skip(1).Aggregate((a,b)=>a/b);
public class DbLazyProxy : IDb
{
private IDb? _real; private readonly string _cs;
public DbLazyProxy(string cs)=>_cs=cs;
private IDb Real=>_real ??= new SqlDb(_cs);
public int Query(string q)=>Real.Query(q);
}
Головна вигода DbLazyProxy:
public class Sum : Expr
{
private readonly Expr _l, _r;
public Sum(Expr l, Expr r)=>(_l,_r)=(l,r);
public override int Eval(Context c) => _l.Eval(c) + _r.Eval(c);
}
Що демонструє клас Sum?
var repeat = Enumerable.Repeat("Hi",3).Select((s,i)=> $"{i}-{s}");]]>Реалізація
var dict = new Dictionary]]>{{1,"one"},{2,"two"},{3,"three"}}
.Where(kv => kv.Key%2==1);
ColorInfo ci = colorFlyweight.Get("#FF00FF");
Навіщо Flyweight у сервісі кольорів?