⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace _1
{
    // "Component"
    abstract class LibraryItem
    {
        private int numCopies;
        public int NumCopies
        {
            get { return numCopies; }
            set { numCopies = value; }
        }
        public abstract void Display();
    }
    // "ConcreteComponent"
    class Book : LibraryItem
    {
        private string author;
        private string title;
        public Book(string author, string title, int numCopies)
        {
            this.author = author;
            this.title = title;
            this.NumCopies = numCopies;
        }
        public override void Display()
        {
            Console.WriteLine(" ------图书 ------ ");
            Console.WriteLine(" 作者: {0}", author);
            Console.WriteLine(" 标题: {0}", title);
            Console.WriteLine("   册: {0}", NumCopies);
        }
    }
    class Video : LibraryItem
    {
        private string director;
        private string title;
        private int playTime;
        public Video(string director, string title,
          int numCopies, int playTime)
        {
            this.director = director;
            this.title = title;
            this.NumCopies = numCopies;
            this.playTime = playTime;
        }
        public override void Display()
        {
            Console.WriteLine(" ----- 软件 ----- ");
            Console.WriteLine(" 项目主管: {0}", director);
            Console.WriteLine(" 名称名称: {0}", title);
            Console.WriteLine(" 软件大小: {0}", NumCopies);
            Console.WriteLine(" 开发周期: {0}", playTime);
        }
    }
    // 装饰
    abstract class Decorator : LibraryItem
    {
        protected LibraryItem libraryItem;
        public Decorator(LibraryItem libraryItem)
        { this.libraryItem = libraryItem; }
        public override void Display()
        { libraryItem.Display(); }
    }
    class Borrowable : Decorator
    {
        protected ArrayList borrowers = new ArrayList();
        public Borrowable(LibraryItem libraryItem)
            : base(libraryItem) { }
        public void BorrowItem(string name)
        {
            borrowers.Add(name);
            libraryItem.NumCopies--;
        }
        public void ReturnItem(string name)
        {
            borrowers.Remove(name);
            libraryItem.NumCopies++;
        }
        public override void Display()
        {
            base.Display();
            foreach (string borrower in borrowers)
                Console.WriteLine(" borrower: {0}", borrower);
        }
    }
    public class DecoratorApp
    {
        public static void Main(string[] args)
        {
            Book book = new Book("图书开发", "技术方案宝典", 10);
            Video video = new Video("软件开发", "瓦斯录音系统", 23, 60);
            book.Display();
            video.Display();
            // Make video borrowable, then borrow and display
            Console.WriteLine(" Video made borrowable:");
            Borrowable borrowvideo = new Borrowable(video);
            borrowvideo.BorrowItem("吉林省明日科技有限公司--图书开发");
            borrowvideo.BorrowItem("吉林省明日科技有限公司--软件开发");
            borrowvideo.Display();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -