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!
Expr ast = Parser.Parse("2*(x+3)");
Чому Parser не входить у патерн Interpreter?
Яку проблему вирішує патерн Фабричний метод (Factory Method)
Принцип відкритості/закритості (Open/Closed Principle) полягає в тому, що програма повинна бути
public class DiGuiFactory : IGUIFactory
{
private readonly IServiceProvider _sp;
public DiGuiFactory(IServiceProvider sp) => _sp = sp;
public IButton CreateButton() => _sp.GetRequiredService
();
public ICheckbox CreateCheckbox() => _sp.GetRequiredService
();
}
Що робить цю фабрику потенційно порушенням принципу Abstract Factory?
var opt = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault };
System.Console.WriteLine(JsonSerializer.Serialize(new { n = 0 }, opt));
byte[] data = JsonSerializer.SerializeToUtf8Bytes(new { x = 3, y = 4 });
var reader = new Utf8JsonReader(data);
reader.Read(); // StartObject
reader.Read(); // PropertyName "x"
reader.Read(); // Value 3
reader.Skip(); // <- ця команда
reader.Read(); // EndObject
System.Console.WriteLine(reader.TokenType);
Який поведінковий патерн використано
class Program
{
static void Main(string[] args)
{
var books = new List<Book> {
new Book("The Stand", "Stephen King", CoverType.Paperback, 35000),
new Book("The Hobbit", "J.R.R. Tolkien", CoverType.Paperback, 25000),
new Book("The Name of the Wind", "Patrick Rothfuss", CoverType.Digital, 7500),
new Book("To Kill a Mockingbird", "Harper Lee", CoverType.Hard, 65000),
new Book("1984", "George Orwell", CoverType.Paperback, 22500) ,
new Book("Jane Eyre", "Charlotte Brontë", CoverType.Hard, 82750)
};
var digitalCoverSpec = new Specification<Book>(book => book.CoverType == CoverType.Digital);
var hardCoverSpec = new Specification<Book>(book => book.CoverType == CoverType.Hard);
var paperbackCoverSpec = new Specification<Book>(book => book.CoverType == CoverType.Paperback);
var extremeBudgetSpec = new Specification<Book>(book => book.PublicationCost >= 75000);
var highBudgetSpec = new Specification<Book>(book => book.PublicationCost >= 50000 && book.PublicationCost < 75000);
var mediumBudgetSpec = new Specification<Book>(book => book.PublicationCost >= 25000 && book.PublicationCost < 50000);
var lowBudgetSpec = new Specification<Book>(book => book.PublicationCost < 25000);
var defaultSpec = new Specification<Book>(book => true);
var publicationProcess = new PublicationProcess();
var ceo = new Employee<Book>("Alice", Position.CEO, publicationProcess.PublishBook);
var president = new Employee<Book>("Bob", Position.President, publicationProcess.PublishBook);
var cfo = new Employee<Book>("Christine", Position.CFO, publicationProcess.PublishBook);
var director = new Employee<Book>("Dave", Position.DirectorOfPublishing, publicationProcess.PublishBook);
var defaultEmployee = new Employee<Book>("INVALID", Position.Default, publicationProcess.FailedPublication);
director.SetSpecification(digitalCoverSpec.And<Book>(lowBudgetSpec));
cfo.SetSpecification(digitalCoverSpec.Or<Book>(paperbackCoverSpec).And<Book>(mediumBudgetSpec.Or<Book>(highBudgetSpec)));
president.SetSpecification(mediumBudgetSpec.Or<Book>(highBudgetSpec));
ceo.SetSpecification(extremeBudgetSpec);
defaultEmployee.SetSpecification(defaultSpec);
director.SetSuccessor(cfo);
cfo.SetSuccessor(president);
president.SetSuccessor(ceo);
ceo.SetSuccessor(defaultEmployee);
books.ForEach(book => director.PublishBook(book));
}
}
public class PublicationProcess
{
public void PublishBook(Book book)
{
book.Publish();
}
public void FailedPublication(Book book)
{
}
}
public enum CoverType
{
Digital,
Hard,
Paperback
}
public interface IPublishable
{
string Author { get; set; }
CoverType CoverType { get; }
decimal PublicationCost { get; set; }
void Publish();
string Title { get; set; }
}
public class Book : IPublishable
{
public string Author { get; set; }
public CoverType CoverType { get; set; }
public decimal PublicationCost { get; set; }
public string Title { get; set; }
public Book(string title, string author, CoverType coverType, decimal publicationCost)
{
this.Author = author;
this.PublicationCost = publicationCost;
this.CoverType = coverType;
this.Title = title;
}
public void Publish()
{
}
public override string ToString()
{
return $"{CoverType} cover '{Title}' by {Author} for {PublicationCost:C2}";
}
}
public interface ISpecification<in T>
{
bool IsSatisfiedBy(T expression);
}
public class Specification<T> : ISpecification<T>
{
private readonly Func<T, bool> _expression;
public Specification(Func<T, bool> expression)
{
this._expression = expression;
}
public bool IsSatisfiedBy(T expression)
{
return this._expression(expression);
}
}
public static class SpecificationExtensions
{
public static Specification<T> And<T>(this ISpecification<T> a, ISpecification<T> b)
{
if (a != null && b != null)
{
return new Specification<T>(expression => a.IsSatisfiedBy(expression) && b.IsSatisfiedBy(expression));
}
return null;
}
public static Specification<T> Or<T>(this ISpecification<T> a, ISpecification<T> b)
{
if (a != null && b != null)
{
return new Specification<T>(expression => a.IsSatisfiedBy(expression) || b.IsSatisfiedBy(expression));
}
return null;
}
public static Specification<T> Not<T>(this ISpecification<T> a)
{
// Check .
return a != null ? new Specification<T>(expression => !a.IsSatisfiedBy(expression)) : null;
}
}
public enum Position
{
CEO,
President,
CFO,
DirectorOfPublishing,
Default
}
public interface IEmployee<T>
{
void PublishBook(T book);
void SetSpecification(ISpecification<T> specification);
void SetSuccessor(IEmployee<T> employee);
}
public class Employee<T> : IEmployee<T> where T : IPublishable
{
private IEmployee<T> _successor;
private readonly string _name;
private ISpecification<T> _specification;
private readonly Action<T> _publicationAction;
private readonly Position _position;
public Employee(string name, Position position, Action<T> publicationAction)
{
_name = name;
_position = position;
_publicationAction = publicationAction;
}
public bool CanApprove(T book)
{
if (_specification != null && book != null)
{
return _specification.IsSatisfiedBy(book);
}
return false;
}
public void PublishBook(T book)
{
if (CanApprove(book))
{
if (_position != Position.Default)
{
}
_publicationAction.Invoke(book);
Logging.LineSeparator();
}
else
{
_successor?.PublishBook(book);
}
}
public void SetSpecification(ISpecification<T> specification)
{
_specification = specification;
}
public void SetSuccessor(IEmployee<T> employee)
{
_successor = employee;
}
}
В JSON дані розділяються
var groups = new[]{ new[]{1}, new[]{2,3}, new[]{4,5,6}}
.SelectMany(a=>a)
.GroupBy(n=>n%2);
]]>public interface IVisitor
{
void Visit(FileLeaf f);
void Visit(FolderComposite d);
}
Навіщо поєднувати Visitor і Composite?