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

推荐订阅源

P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
B
Blog
月光博客
月光博客
博客园 - 【当耐特】
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
博客园 - Franky
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
B
Blog RSS Feed
H
Help Net Security

博客园 - 酸辣大白菜

排序算法 终结版 (C#) --数据结构 用于主题检测的临时日志(bf1783d2-27ab-4079-a1c6-08a661824368 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) windows mobile网络设备 ------------- DMProcessConfigXML android 系统配置 常用命令 - linux qt 信号与槽机制 用于主题检测的临时日志(b9c62a98-6395-4fa6-b30d-70521beaf329 - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 无绳电话系统 C++ 数据类型转换 关于内存泄漏检测 发布一个边看电子书边听英语的小工具 C++ 工厂模式 xml 解析库 msxml6.dll IE 8 与vs2005的兼容性问题 c++ vector用法 关于msxml.dll 音频驱动的3种模式 download WM6.5.3 SDK about CreateFileMapping on wince about MarshalledBuffer
做人学会说NO,写程序学会说NULL。----------设计模式
酸辣大白菜 · 2011-01-06 · via 博客园 - 酸辣大白菜

如果朋友要向你借钱,你没有钱但你没有跟朋友说,朋友以为你有钱借给,于是朋友急用钱,你却拿不出。
朋友借钱消费也就罢了,如果是看病,那可就耽误大事了!!

呵呵。
做人学会说NO,写程序学会说NULL。
 


namespace NullObject
{

    public abstract class Friend
    {
        public abstract bool IsHaveMoney();
        public abstract void Lend();
        public static readonly Friend NULL = new NullFriend(); //会说null 的朋友

        private sealed class NullFriend : Friend
        {
            public override bool IsHaveMoney()
            {
                Console.WriteLine("sorry, i have not money!\r\n");
                return false;
            }
            public override void Lend()
            {
                Console.WriteLine("NullFriend: no  lend();\r\n");
            }
        }
    }

    class Consumer
    {
        public static Friend getFriends()
        {
            return Friend.NULL;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Friend friend = Consumer.getFriends();
            if (friend.IsHaveMoney())
            {
                friend.Lend();
            }
            Console.WriteLine("end ;\r\n");
        }
    }
}