✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Який структурний патерн використано
class Program
{
static void Main(string[] args)
{
var spiralBinding = new SpiralBinding();
var fantasyBook = new FantasyBook("The Name of the Wind", "Patrick Rothfuss", spiralBinding);
var sciFiBook = new ScienceFictionBook("Dune", "Frank Herbert", spiralBinding);
}
}
interface IBinding
{
string Name { get; }
}
class Binding : IBinding
{
public string Name
{
get
{
return this.GetType().Name;
}
}
}
class PerfectBinding : Binding { }
class SpiralBinding : Binding { }
class SaddleStitchBinding : Binding { }
interface IBook
{
string Author { get; set; }
Binding Binding { get; set; }
string Title { get; set; }
}
class Book : IBook
{
public string Author { get; set; }
public Binding Binding { get; set; }
public string Title { get; set; }
public Book(string title, string author, Binding binding)
{
Author = author;
Binding = binding;
Title = title;
Console.WriteLine($"Created {this.GetType().Name} of \"{title}\" by {author} using {binding.Name}.");
}
}
class MysteryBook : Book
{
public MysteryBook(string title, string author, Binding binding) : base(title, author, binding) { }
}
class FantasyBook : Book
{
public FantasyBook(string title, string author, Binding binding) : base(title, author, binding) { }
}
class ScienceFictionBook : Book
{
public ScienceFictionBook(string title, string author, Binding binding) : base(title, author, binding) { }
}