Chapter 6. Methods
This chapter discusses several aspects of method design:
how to treat parameters and return values, how to design method signatures, and
how to document methods. Much of the material in this chapter applies to
constructors as well as to methods. Like Chapter 5, this chapter focuses on
usability, robustness, and flexibility.
Item 23: Check parameters for validity
Most methods and constructors have some restrictions on
what values may be passed into their parameters. For example, it is not
uncommon that index values must be nonnegative and object references must be non-null.
You should clearly document all such restrictions and enforce them with checks
at the beginning of the method body.
This is a special case of the general principle, and you
should attempt to detect errors as soon as possible after they occur. Failing
to do so makes it less likely that an error will be detected and makes it
harder to determine the source of an error once it has been detected.
分享到:
相关推荐
Chapter 6. Methods Chapter 7. Interfaces Chapter 8. Goroutines and Channels Chapter 9. Concurrency with Shared Variables Chapter 10. Packages and the Go Tool Chapter 11. Testing Chapter 12. Reflection...
Chapter 6. Capstone: The Vigenère Cipher Unit 3 - BUILDING BLOCKS Chapter 1. Functions Chapter 2. Methods Chapter 3. First-Class Functions Chapter 4. Capstone: Temperature Tables Unit 4 - ...
Chapter 6. Arrays Chapter 7. Regular Expressions Chapter 8. Methods Chapter 9. Style Chapter 10 Beautiful Features Appendix A. Awful Parts Appendix B. Bad Parts Appendix C. JSLint Appendix D. Syntax ...
Chapter 6. Encapsulating Data and Exposing Methods in Java Chapter 7. Using Java Methods to Communicate Chapter 8. Using Java Constructors Chapter 9. Inheriting Code and Data in Java Chapter 10. ...
Chapter 6. Linear and Invariant Discrete-Time Systems Chapter 7. Infinite Impulse Response Filters Chapter 8. Finite Impulse Response Filters Chapter 9. Detection and Estimation Chapter 10. Power ...
Chapter 6. Operators Chapter 7. Flow Control Chapter 8. Functions and Closures Chapter 9. Classes and Structures Chapter 10. Methods Chapter 11. Access Control Chapter 12. Inheritance Chapter 13. ...
Chapter 6. Swift Data Types, Constants and Variables Chapter 7. Swift Operators and Expressions Chapter 8. Swift Flow Control Chapter 9. The Swift Switch Statement Chapter 10. An Overview of Swift 2 ...
老师推荐以及教学用书,是英文版本的 ...Chapter 6. Methods: A Deeper Look Chapter 7. Arrays Chapter 8. Classes and Objects: A Deeper Look Chapter 9. Object-Oriented Programming: Inheritance 等29章
Chapter 6. XML Chapter 7. RPC and SOAP Services Chapter 8. REST Chapter 9. Webhooks Chapter 10. HTTP Tools Chapter 11. Maintainable Web Services Chapter 12. Making Service Design Decisions Chapter 13....
Chapter 6. Interfaces and Inner Classes Chapter 7. Graphics Programming Chapter 8. Event Handling Chapter 9. User Interface Components with Swing Chapter 10. Deploying Applications and Applets Chapter...
Chapter 6. Identifying Groups Of Data Using Clustering Methods Chapter 7. Simulation Of Human Thinking - Artificial Neural Networks Chapter 8. Improving The Performance Of The Machine Learning Model -...
Chapter 6. Design patterns with first-class functions Chapter 7. Function decorators and closures Part IV. Object Oriented Idioms Chapter 8. Object references, mutability and recycling Chapter 9. A ...
Title: C++ Language ...Chapter 6. Classes Chapter 7. Overloading Chapter 8. Derived Classes Chapter 9. Templates Chapter 10. Exception Handling Chapter 11. The IO Library Chapter 12. The Preprocessor
Chapter 6. Adding NoSQL Persistence to Storm Chapter 7. Cassandra Partitioning, High Availability, and Consistency Chapter 8. Cassandra Management and Maintenance Chapter 9. Storm Management and ...