- 浏览: 746620 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
2011.04.07
Objects and Data Structures
Procedural code (code using data structures) makes it easy to add new functions without
changing the existing data structures. OO code, on the other hand, makes it easy to add
new classes without changing existing functions.
The complement is also true:
Procedural code makes it hard to add new data structures because all the functions must
change. OO code makes it hard to add new functions because all the classes must change.
So, the things that are hard for OO are easy for procedures, and the things that are
hard for procedures are easy for OO!
In any complex system there are going to be times when we want to add new data
types rather than new functions. For these cases objects and OO are most appropriate. On
the other hand, there will also be times when we’ll want to add new functions as opposed
to data types. In that case procedural code and data structures will be more appropriate.
Mature programmers know that the idea that everything is an object is a myth. Sometimes
you really do want simple data structures with procedures operating on them.
The Law of Demeter
There is a well-known heuristic called the Law of Demeter that says a module should not
know about the innards of the objects it manipulates.
They are indicative of a muddled design whose authors are unsure of—or worse, ignorant of—whether they need protection from functions or types.
i look on indicative of as a compound preposition.
2011.04.12
public class PerDiemMealExpenses implements MealExpenses { public int getTotal() { // return the per diem default } }
This is called the SPECIAL CASE PATTERN [Fowler]. You create a class or configure an
object so that it handles a special case for you. When you do, the client code doesn’t have
to deal with exceptional behavior. That behavior is encapsulated in the special case object.
If you work in a code base
with code like this, it might not look all that bad to you, but it is
bad! When we return null, we are essentially creating work for ourselves and foisting
problems upon our callers. All it takes is one missing null check to send an application
spinning out of control
.
If you code this way, you will minimize the chance of NullPointerExceptions and your
code will be cleaner.
you should avoid passing null in your code whenever possible.
Don't return null, don't pass null.
In most programming languages there is no good way to deal with a null that is
passed by a caller accidentally. Because this is the case, the rational approach is to forbid
passing null by default. When you do, you can code with the knowledge that a null in an
argument list is an indication of a problem, and end up with far fewer careless mistakes.
Clean code is readable, but it must also be robust.
These are not conflicting goals. We can
write robust clean code if we see error handling as a separate concern, something that is
viewable independently of our main logic. To the degree that we are able to do that, we can
reason about it independently, and we can make great strides in the maintainability of our
code.
Learning tests verify that the third-party packages we are using work the way we
expect them to
.
Without these boundary tests to ease the migration, we might be tempted to stay with the old version longer than we should.
We had a pretty good idea of where our world ended and the new world began. As we
worked, we sometimes bumped up against this boundary. Though mists and clouds of
ignorance obscured our view beyond the boundary, our work made us aware of what we
wanted the boundary interface to be.
In the Figure above, you can see that we insulated the CommunicationsController classes
from the transmitter API (which was out of our control and undefined). By using our own
application specific interface, we kept our CommunicationsController code clean and
expressive. Once the transmitter API was defined, we wrote the TransmitterAdapter to
bridge the gap
. The ADAPTER encapsulated the interaction with the API
and provides a
single place to change when the API evolves
.
Interesting things happen at boundaries. Change is one of those things. Good software
designs accommodate change without huge investments and rework. When we use code
that is out of our control, special care must be taken to protect our investment and make
sure future change is not too costly.
Code at the boundaries needs clear separation and tests that define expectations. We
should avoid letting too much of our code know about the third-party particulars. It’s better
to depend on something you control than on something you don’t control, lest it end up
controlling you.
We manage third-party boundaries by having very few places in the code that refer to
them. We may wrap them as we did with Map, or we may use an ADAPTER to convert from
our perfect interface to the provided interface. Either way our code speaks to us better,
promotes internally consistent usage across the boundary, and has fewer maintenance
points when the third-party code changes.
发表评论
-
effective java 2nd Item 18
2012-08-15 15:45 1218Prefer interfaces to abstract ... -
Head First HTML with CSS and XHTML
2012-03-27 14:50 974i finished it by fast reading a ... -
head first jquery
2012-03-22 10:21 1136Thursday, March 22, 2012 fi ... -
Software Architecture Design Patterns in Java
2011-05-13 22:53 813to be continued... -
Effective Java 2nd edition
2011-04-25 16:19 1017Item 3: Enforce the singleton p ... -
Clean Code: chapter 13~15
2011-04-20 17:20 1024What follows is a series of p ... -
Clean Code: chapter 11~12
2011-04-15 09:35 1054The startup process is a concer ... -
Clean Code: chapter 9~10
2011-04-12 11:49 997Yes, we’ve come a long way; but ... -
Open Stanford Course: programming methodology 04
2011-04-05 11:52 922because this is sort of pre thi ... -
Open Stanford Course: programming methodology 03
2011-04-04 13:01 951any questions to start off with ... -
Clean Code: chapter 1~5
2011-04-02 11:26 930you should try several diffe ... -
Open Stanford Course: programming methodology 02
2011-03-31 00:30 975If you are stuck in the back, j ... -
Open Yale Course: Frontiers of Biomedical Engineering 01
2011-03-30 11:21 906http://www.verycd.com/topics/28 ... -
Open Stanford Course: programming methodology 01
2011-03-25 11:00 927you can pick them up on the ... -
Java Puzzler
2011-03-24 23:58 10622011.03.24 now i've been thr ... -
How Computers Work
2011-03-04 09:58 1016Yes, im at last reading this fa ... -
The Java Language Specification Third Edition
2011-01-25 10:36 845starting day: 2011.01.25 -
Tricks of the Java Programming Gurus
2011-01-24 11:22 921In the world of programming, t ... -
Thinking in Java Fourth Edition
2011-01-17 15:59 988以前这些经典书籍都零零散散地阅览过,现在准备重新精读一遍,随时 ...
相关推荐
Chapter 1 Clean Code Chapter 2 Meaningful Names Chapter 3 Functions Chapter 4 Comments Chapter 5 Formatting Chapter 6 Objects and Data Structures Chapter 7 Error Handling Chapter 8 Boundaries Chapter ...
Robert lays out 24 patterns of thought and design that tend to produce faster, more reliable, and easier to maintain code without noticeably increasing the difficulty or decreasing the speed of coding...
But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to ...
Chapter 8: Model Tests Chapter 9: Controller Tests 1 Chapter 10: Mocks Chapter 11: Controller Tests 2 Chapter 12: Test Suites Chapter 13: Testing from Command Line Chapter 14: Goodies
CleanCode4Noobs 罗伯特·塞西尔·马丁(Robert Cecil Martin)编写的《清洁代码:敏捷软件技巧手册》的摘要。 内容 参考 Robert C. Martin,“清洁代码:敏捷软件Craft.io手册” 如何贡献 贡献使开源社区成为了一...
Over 90 hands-on recipes to successfully build ...Chapter 8: Handling Typical Build Requirements Chapter 9: Multimodule Projects Chapter 10: Java Development with Maven Chapter 11: Advanced Maven Usage
Chapter 8: Behaviors Part 1 Chapter 9: Behaviors Part 2 Chapter 10: Player Input Chapter 11: Game 2 – Space Shooter Chapter 12: Audio Chapter 13: The Expression Editor Chapter 14: Collisions and ...
The first chapter discusses briefly the components and the ideas behind this software structure, while chapter 2 runs through a concrete example of clean architecture for a very simple web service....
There are eight directories, ...Chapter 8: The Common Language Runtime Assemblies Attributes collectionBinary ildasm reflection serialize tester timer Pictures Textfiles Xmlfiles
### SCJP Sun® Certified Programmer for Java™ 6 Study Guide Chapter 5: Flow Control, Exceptions, and Assertions #### Certification Objectives Overview In this chapter, we delve into the critical ...
Chapter 8: Finding Patterns – Market Basket Analysis Using Association Rules Chapter 9: Finding Groups of Data – Clustering with k-means Chapter 10: Evaluating Model Performance Chapter 11: ...
Title: Less Web Development Essentials, 2nd Edition Author: Bass Jobsen ...Chapter 6: Using The Bootstrap 3 Frontend Framework Chapter 7: Less With External Applications And Frameworks
Key Features Learn how to design Single Page ...Chapter 8: Third-Party Authentication and External Providers Chapter 9: User Registration and Account Edit Chapter 10: Finalization and Deployment
Chapter 6. Maintaining Your Test Suite Chapter 7. Executable Documentation with doctest Chapter 8. Extending unittest with nose2 Chapter 9. Unit Testing Patterns Chapter 10. Tools to Improve Test-...
Create funky, impressive applications using Swift About This Book Learn Swift language features quickly, with playgrounds and in-depth examples Implement real iOS ...Chapter 8: Completing Cube Runner
**Chapter 8: Objects** - **Object-Oriented Programming (OOP) Concepts:** Explanation of OOP concepts, including classes, objects, inheritance, encapsulation, and polymorphism. - **Defining Classes and...