dir.by  
Поиск >>

Компьютер, программы
→
Patterns, Design Patterns | OOP Principles | Code refactoring
 Прототип (Prototype) это порождающий шаблон проектирования 
посмотрели 4157 раз
обновлено: 30 March 2021
Прототип — это паттерн, который позволяет копировать объекты, не вдаваясь в подробности их реализации.
Пример
  C#  
class Program
{
     static void Main(string[] args)
     {
          IFigure figure = new Rectangle(30,40);
          IFigure clonedFigure = figure.Clone(); // прототип

          figure = new Circle(30);
          clonedFigure=figure.Clone(); // прототип
     }
}

interface IFigure
{
     IFigure Clone();
}

class Rectangle: IFigure
{
     int width;
     int height;

     public Rectangle(int w, int h)
     {
          width = w;
          height = h;
     }

     public IFigure Clone()
     {
          return new Rectangle(this.width, this.height);
     }
}

class Circle : IFigure
{
     int radius;

     public Circle(int r)
     {
          radius = r;
     }

     public IFigure Clone()
     {
          return new Circle(this.radius);
     }
}
 
← Previous topic
Singleton is a generative design pattern
 
Next topic →
The Builder is the generative design pattern
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
Introduction
• What is a subclass or child class or descendant of a class? What is a parent class?
Principles of OOP
• What is Object-Oriented Programming? Principles: abstraction, encapsulation, inheritance, polymorphism
Code refactoring
• What is code refactoring?
Design patterns
Generative patterns
• The Factory Method is a generative design pattern
• The Abstract Factory is a generative design pattern
• Singleton is a generative design pattern
• Prototype is a generative design pattern
• The Builder is the generative design pattern
<BR>
Patterns of behavior
• Strategy is a behavioral design pattern
S.O.L.I.D. (5 principles of program design)
• What is SOLID?
• Single Responsibility Principle SOLID Design
• Open/Closed Principle SOLID Design

  Ваши вопросы присылайте по почте: info@dir.by