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

推荐订阅源

罗磊的独立博客
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
B
Blog
博客园_首页
博客园 - 司徒正美
有赞技术团队
有赞技术团队
博客园 - 聂微东
I
InfoQ
美团技术团队
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog

博客园 - 酸辣大白菜

排序算法 终结版 (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");
        }
    }
}