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 RateLimitDecorator : IApi
{
private readonly IApi _inner;
private readonly TokenBucket _bucket;
public RateLimitDecorator(IApi a, int m) => (_inner, _bucket) = (a, new TokenBucket(m));
public Response Call(string ep)
=> _bucket.Take() ? _inner.Call(ep) : Response.TooManyRequests();
}
Що спільного у всіх Decorator’ів?
public interface INode { int Size(); }
public sealed class FileLeaf : INode
{
private readonly int _bytes;
public FileLeaf(int bytes) => _bytes = bytes;
public int Size() => _bytes;
}
public sealed class FolderComposite : INode
{
private readonly List
_children = new();
public void Add(INode n) => _children.Add(n);
public int Size() => _children.Sum(c => c.Size());
}
Який патерн ілюструє цей код?
var buffer = new ArrayBufferWriter<byte>();
using (var w = new Utf8JsonWriter(buffer, new JsonWriterOptions { Indented = true }))
{
w.WriteStartArray();
w.WriteNumberValue(1);
w.WriteEndArray();
}
System.Console.WriteLine(System.Text.Encoding.UTF8.GetString(buffer.WrittenSpan).Count(c => c=='\n'));
Патерн Посередник (Mediator) реалізує зв'язок
var list = new[] { "ab", "abc", "abcd" };
var len = list.Select(s => s.Length).Where(l => l > 2).Max();
]]>public Report Build()
{
if (_sections.Count == 0)
throw new InvalidOperationException("Report must have at least one section");
return _report;
}
Що демонструє ця перевірка в Build()?
public class Const : Expr
{
public int Value { get; }
public Const(int v)=>Value=v;
public override int Eval(Context _) => Value;
}
Чому Context ігнорується у Const.Eval?
var data = new[] { "abc", "de", "fghi" };
var query = data.Where(s => s.Contains("e") || s.Contains("g")).OrderByDescending(s => s.Length).First();
]]>public sealed class Singleton
{
private static Singleton instance;
private Singleton() { }
public static Singleton Instance
{
get
{
if (instance == null)
instance = new Singleton();
return instance;
}
}
}
Яку проблему має цей код?
public class Macro : ICommand
{
private readonly IReadOnlyList
_list;
public Macro(params ICommand[] cmds) => _list = cmds;
public void Execute() => _list.ToList().ForEach(c => c.Execute());
}
Правильне твердження: