|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
Easy Learn Java: Programming Articles, Examples and Tips - Page 361
Previous
1060 Stories (530 Pages, 2 Per Page)
Next
Design By Contract
|
Bertrand Meyer orginated a programming methodology called Design by Contract,
which has become popular in some groups. In addition to specifying programming
code to carry out the operations of a function (method), the programmer also
specifies:
- Preconditions - assumptions the function makes. These are usually
expressed as statements that must be true about the parameters. This is the
part of the "contract" that the caller must agree to.
- Postconditions - conditions that are true when it finishes. These
conditions define the responsibilities of the function, and are the part of
the contract that the function agrees to.
- Invariants - conditions that should be true of a class in general
(class invariants. It's sometimes applied to loops (loop
invariants). These seem to be generally less useful than pre- and
postconditions.
Design benefits
The strength of this programming methodology is that it gets the programmer to
think clearly about what a function does, and it provides documentation for the
caller.
Programming language support for Design by Contract
A few programming languages, eg Eiffel and Sather
Sather home page,
implement pre- and postconditions in executable code so that they are checked at
run time. Most programming language don't have such support, so programmers who
want to use pre- and postconditions often write comments documenting the
conditions. This is not an ideal situation because the comments aren't verified
automatically, and they may not even be consistent with the actual code.
Assertions
Perhaps the closest one can come in pure Java to implementing pre- and
postconditions is to use the assert statement.
Trademarked?
It seems that Bertrand Meyer's company, Interactive Software Engineering, has
trademarked the phrase "Design by Contract".
Further reading
Building bug-free O-O software: An introduction to Design by Contract
8 comments | | Score: 0
|
Posted by jalex on Friday, May 20, 2005 (00:00:00) (2646 reads)
|
Development Techniques
|
Beginning programming textbooks usually concentrate on two topics: the
programming language and the general ideas the programming language constructs
implement. This is good, but there are basic program development techniques that
are often not taught, but which make program development much easier, and which
are used by professional programmers for maximum effectiveness.
Basic techniques
Every programmer, beginner or more advanced, should use these techniques where
possible.
- Tools - Choose good tools and learn them well.
- Indentation - Be scrupulous about indentation. See
Java Coding Standards.
- Start - Start with a working program.
- Small increments - Work in small increments.
- Pair programming - Work with someone else.
Intermediate techniques
All of the above plus
- Save your programs -- you may be able to use them as the nucleus for
another program.
- Create you own library. When you write a good general class or method,
add it to this library.
- Refactor (rewrite) parts of a program if you realize there is a
better way. A better written program will be less likely to have bugs and
will be easier to extend for the next iteration.
- Use an IDE (Integrated Development Environment), eg, NetBeans,
Eclipse, or JBuilder (A Java IDE requires learning, and therefore may not be
a good choice for beginning programmers. However, after you are comfortable
developing simple Java programs with a text editor and the JDK, the
advantages of an IDE for creating user interfaces and debugging can be
significant. As with all tools, learn to use it well. Check the menus for
options that might be useful.
1 comment | | Score: 0
|
Posted by jalex on Thursday, May 19, 2005 (00:00:00) (2365 reads)
|
|
|