惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Privacy International News Feed
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
C
Cisco Blogs
T
The Blog of Author Tim Ferriss
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
博客园 - Franky
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
T
Tor Project blog
B
Blog RSS Feed
Recorded Future
Recorded Future
Scott Helme
Scott Helme
美团技术团队
V
V2EX
V
Visual Studio Blog
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
D
DataBreaches.Net
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
L
LangChain Blog
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园_首页
P
Privacy & Cybersecurity Law Blog

博客园 - tf.li

清理MVC4 Internaet 项目模板清理 SQL2014 尝试读取或写入受保护的内存。这通常指示其他内存已损坏 nodejs 环境配置技巧 mongdb window 服务安装批处理 bower 安装后 jade 引用404问题 我的Prototype模式框架 转自CnBeta 令人深思 [译稿]为什么我们不要 .NET 程序员 JSON.NET、WebService与JQuery协同工作 我修改的IP地址掩码 呵呵~~开心 Ext.Ajax.request 传值问题 从小做大之一---------一切从建模开始 [求助]关于文本行转列的疑问~~ To Terrylee 我的设计模型之小议工厂模式 我的设计模型之装饰者模式 我对线程池的一点理解 面向接口编程之惑 第二版 面向接口编程之惑 我的设计模型之适配器模式
我的设计模型之简单工厂
tf.li · 2008-05-10 · via 博客园 - tf.li

我的设计模型之简单工厂

抽象工厂模型 了解设计模型的人都该清楚啊 代码自己打一下 比较清楚啊

  using

 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 抽象工厂
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            Console.WriteLine(
"请输入你要购买的水果:");
            
string FruitName = Console.ReadLine();
            IFruit Fruit 
= null;
            FruitFactory MyFactory 
= new FruitFactory();
            
switch (FruitName) 
                
case "苹果":
                    Fruit 
= MyFactory.MakeApple();
                    
break;
                
case "橘子":
                    Fruit 
= MyFactory.MakeOrange();
                    
break;
                
default:
                    Console.WriteLine(
"别瞎写 就两种水果!");
                    
break;
            }

            Console.ReadLine();
        }

    }

    
interface IFruit 
    
    }

    
public class Apple : IFruit 
     
public Apple(){
         Console.WriteLine(
"An Apple is Got!");
      }

    }

    
public class Orange : IFruit {
        
public Orange() {
            Console.WriteLine(
"An Orange is Got!");
        }

    }

    
public class FruitFactory {
        
public Apple MakeApple() {
            
return new Apple();
        }

        
public Orange MakeOrange() {
            
return new Orange();
        }

    }

}

posted @ 2008-05-10 15:31  tf.li  阅读(382)  评论(1)    收藏  举报

刷新页面返回顶部