zoukankan      html  css  js  c++  java
  • prototypephotoarchive.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using CompositePattern;
    using PrototypePattern;

    //  Prototype Pattern Pattern        August 2007
    //  Makes use of the Photo Librray examples
    // Shares (i.e. deep copys) parts of the hierarchy, then makes changes
     
      // The Client
     class CompositePatternExample {
        
        static void Main () {
            IComponent <string> album = new Composite<string> ("Album");
            IComponent <string> point = album;
            IComponent <string> archive = new Composite<string> ("Archive");
            string [] s;
            string command, parameter;
          // Create and manipulate a structure
            StreamReader instream = new StreamReader("prototype.dat");
            do {
              string t= instream.ReadLine();
              Console.WriteLine("\t\t\t\t"+t);
              s = t.Split();
              command = s[0];
              if (s.Length>1) parameter = s[1]; else parameter = null;
              switch (command) {
                  case "AddSet"   :   IComponent <string> c =
                                                    new Composite <string> (parameter);
                                             point.Add(c);
                                             point = c;
                                            break;
                  case "AddPhoto":  point.Add(new Component <string> (parameter));
                                           break;
                  case "Remove"   : point = point.Remove(parameter);
                                           break;
                  case "Find"        :  point = album.Find(parameter);  break;
                  case "Display"    :  if (parameter==null)
                                                Console.WriteLine(album.Display(0));
                                            else
                                                Console.WriteLine(archive.Display(0));
                                            break;
                  case "Archive"     :  archive = point.Share(parameter,archive); break;
                  case "Retrieve"  :  point = archive.Share(parameter,album); break;
                  case "Quit"        : break;
            }

        } while (!command.Equals("Quit"));
        }
    }
    /*Output
        AddSet Home
                    AddPhoto Dinner.jpg
                    AddSet Pets
                    AddPhoto Dog.jpg
                    AddPhoto Cat.jpg
                    Find Album
                    AddSet Garden
                    AddPhoto Spring.jpg
                    AddPhoto Summer.jpg
                    AddPhoto Flowers.jpg
                    AddPhoto Trees.jpg
                    Display
    Set Album length :2
    --Set Home length :2
    ----Dinner.jpg
    ----Set Pets length :2
    ------Dog.jpg
    ------Cat.jpg
    --Set Garden length :4
    ----Spring.jpg
    ----Summer.jpg
    ----Flowers.jpg
    ----Trees.jpg

                    Find Pets
                    Archive Pets
                    Display Archive
    Set Archive length :1
    --Set Pets length :2
    ----Dog.jpg
    ----Cat.jpg

                    Find Album
                    Remove Home
                    Find Album
                    Remove Garden
                    Display
    Set Album length :0

                    Retrieve Pets
                    Display
    Set Album length :1
    --Set Pets length :2
    ----Dog.jpg
    ----Cat.jpg

                    Quit
    */
     


  • 相关阅读:
    python操作redis之hash操作
    mongodb数据库分片实现链接
    python连接redis数据库的两种方式
    python操作rabbitmq实现消息过滤接收
    python操作rabbitmq实现广播效果
    关于java和python同时使用rabbitmq时队列同名问题的探讨
    java操作rabbitmq实现简单的消息发送(socket编程的升级)
    python使用rabbitmq实现简单的消息转发
    optiongroup标签选项组
    day05_日常SQL练习(一)
  • 原文地址:https://www.cnblogs.com/shihao/p/2490430.html
Copyright © 2011-2022 走看看