摘要
在Java程序设计中,经常会遇到java.lang.NullPointerException空指针异常,在客户端总是需要判断某一对象是否为空对象,这使得客户端掌握了主动权,且程序不够友好。文章从这些常见的问题出发,分析了一个在经典的23种软件设计模式以外的模式——空对象模式,通过图书管理的场景引出问题,并合理地运用空对象模式对问题进行分析和解决,讨论了空对象模式的实现方式及应用场景,阐述了对空对象模式的优缺点分析与对软件设计模式的深入理解。
In Java programming, we often encounter java.lang.NullPointerException, and in the client end, there is always need to judge whether an object is a null object, which makes the client master grasp the initiative, and the program is not friendly enough.From these common problems, this paper analyzes a pattern other than the classic 23 software design patterns-null object pattern.Through the scene of book management, some problems are pointed out. Therefore, this paper reasonably uses the null object pattern to analyze and solve the problems, discusses the realization and application scenarios of the null object pattern, and expounds the advantages and disadvantages of the null object pattern and the deep understanding of the software design pattern.
作者
汤致轩
姚圣扬
TANG Zhixuan;YAO Shengyang
出处
《科技创新与应用》
2020年第30期1-5,共5页
Technology Innovation and Application
关键词
空对象模式
设计模式
特殊对象
软件工程
JAVA
null object pattern
design patterns
special objects
software engineering
Java