password
username
Sponsored by CakeMail, an email marketing software.
Newsletter preview

Javalobby logo image
Tuesday, December 11, 2007 

Make Applications More Valuable with Caché

InterSystems Caché® is the innovative object database that runs SQL faster than relational databases. Caché is lightning fast, massively scalable, ultra-reliable, requires little administration, and its built-in RAD environment brings your applications to market faster.

Download Caché for free now.

 Perspective


Be sure and
check out a
No Fluff Just Stuff
Java conference
coming your way!

2/08-2/10 San Jose 2/29-3/02 Milwaukee
3/07-3/09 St. Louis
3/14-3/16 Minneapolis
3/28-3/30 Omaha
4/04-4/06 Boston
4/11-4/13 San Diego
4/11-4/13 Portland
4/18-4/20 Jersey City



One Free Ebook a Day for 15 Days!

Click to join the random drawing

Happy Holidays from Manning!

 
 A Developer's Perspective
 Next section
Mario Gleichmann is a freelance developer, located in Germany. He has more than 8 years experience in designing and developing large scale enterprise systems, mainly within the Java platform under Java EE. He strongly believes in 'brain driven development' and is therefore open minded to all sorts of ideas in the field of software development.

Rick Ross, JavaLobby Founder TDD and Design By Contract - friend or foe?
By Mario Gleichmann

In this column I’ll try to answer a legitimate question: why do we need contracts (in the sense of invariants, pre- and post-conditions) when we’ve got unit tests right at hand that could also test the stated conditions?

In fact, it's very tempting to see unit tests as an all-embracing instrument to check and show that a class will behave correctly, making contracts unnecessary.

I’ll try to show you that unit tests (as an instrument for test driven development) and contracts (as an instrument for Design By Contract) indeed share the same goals but aren't competing techniques, rather than methods that could complement each other.

It’s not about verification - it’s about specification
First of all, we have to clarify a potential misconception: unit tests as an instrument in the sense of Test Driven Development (TDD) aren’t that much about verification of a correct implementation rather than about a specification of how a unit should behave. In fact, it’s the specification (not the verification) that will drive development. You can see the result of this core idea in the rise of Behaviour Driven Development (BDD) that mainly tries to find an adequate vocabulary to write down specifications (that of course can be verified automatically) in an easy natural way, refocusing on how a component should behave under certain conditions.

On the other side, Design by Contract is also about specifying the design, in terms of the behaviour of your components. A contract asserts truths about the design of your code in the form of runtime tests placed within the contracted units itself. These assertions will be checked as the thread of execution passes through the parts of those components, and will fire if they don’t hold.

That said, both methods are motiviated by the same purpose - the specification of a system that will drive its design.

Don't Get Carried Away
As said, the goal of bdd is to refocus on the specification of a component. The other way around, it means that it might be easy to lose direction within tdd, risking to set focus on testing and verification. I have to admit that I walked into this trap more than once in the past. Of course the whole vocabulary (test, testcase, testsuite, etc.) makes you believe that it’s about testing. It’s easy to become addicted to this idea, so even writing tests after implementation seems ok in this sense. That’s no longer possible if you see tests as specification: you firstly have to have a specification on what a component is intended to do - you can’t start with an implementation until that specification exists.

Is the same true for Design by Contract? Is the contract metaphor misleading? Of course you could also define your contract afterwards, so again development of a component isn't driven by its specification. But the contract metaphor uses a more appropriate vocabulary. With invariants, pre- and post-conditions, it’s clearly about the specification of the intended behaviour - the risk of seeing a contract as a tool for verification might be much less.

Collaboration includes clients and supplier
There’s a special area where contracts are able to provide real benefits in regard to unit tests: oftentimes unit tests specify only the behaviour of a component as a supplier, that means the test asserts mostly the stated effects (the post-conditions of a method). That’s perfectly legal: most of the prospective clients may be unknown to the designer of the component or doesn’t exist yet. Since the client is responsible for the adherence of preconditions it even should not be the in the job of the supplier.

A contract on the other hand also specifies the constraints under which it’s legal to call a method (the preconditions). Since contracts act on runtime, those preconditions will also be regarded when it comes to collaboration between an arbitrary client and the supplier component. The following points show some aspects of this holistic view:

Reliance on a proper context
Most developers (including me) tend to insert guard clauses in their code despite having unit tests. They don’t seem to trust in the context in which the method gets called (that’s of course a good idea if the context can’t be foreseen). But you’ll even find this fact in environments where the same team controls the whole context. That may be also because of the before mentioned lack of knowledge about all clients that may call your component, especially in teams with limited communication. Another one might be the local (specification / test in a different file than the component) and the temporal (tests at design time - collaboration at runtime) 'distance' between the code and the test.

Leaving contracts aside, the code (as part of the public interface of a component) you can rely on at runtime, seems to increase reliablity in the running context. This may be because of...

Support of Defensive Programming
With Design by Contract, contracts automatically protect methods from improper usage, like illegal arguments (in the simplest case) in the real hard world, checking potentially a wider range of collaborations than a test ever can do (tests cannot show the absence of defects, it can only show that defects are present). Like Bertrand Meyer said: a test checks one (or a limited set of) case(s). A contract describes the abstract specification for all cases.

That said, preconditions that will work at runtime, making guard clauses in a way redundant, because the method can rely that it’s called in a proper way. That’s a runtime feature you can’t achieve with unit tests. They could only check or specify how a component should behave if it’s called in an improper way (for example by expecting to throw an exception, which becomes a post-condition). But this one wouldn’t free you to write additional guard clauses.

Clear Reliable Documentation
While tests can be seen as an additional artifact that specifies the expected behaviour of a component, contracts form part of the public (client-) view of a class - they are part of the public interface. Personally, I’m lazy - I want to recognize the core behaviour of a building block by looking at its interface / signature, not studying an amount of code be it the building block itself or a test - but of course there are also other preferences that prefer a split between specification and implementation.

Of course those contracts are more than documentation, since assertions are checked at runtime, thereby testing that the stated contracts are consistent with what the routines actually do.

Integration 'tests' for free
This one follows directly from the initial point, when regarding collaboration between clients and suppliers: having contracts that can be turned on and off makes it very easy to test and retest parts of a program. It allows you for instance to continue to test class A while you are working on class B, in case there are any interactions you did not foresee. Of course, this is a kind of integration ‘testing’ - it’s not about the specification of the behaviour of a single component but more about collaboration between a set of components and most of the time not in the scope of unit tests.

Clear Design
A contract's condition is an equivalent description of the algorithm used in a function, but written in an orthogonal manner, so thinking about such matters as pre-, post-conditions and invariants help to make the concept of a class more explicit. It might encourage you to think about the conceptual model of a building block. That might lead to a clear design: obligations and benefits are shared between client and supplier and are clearly stated.

The limitations on the use of a method are clearly expressed and the consequences of calling it illegally are clear, so programmers are encouraged not to build routines that are too general, but to design classes with small single-purpose routines. While TDD guides you more towards loosely coupled building blocks (because it hurts when trying to test a tightly coupled component in isolation), DBC guides you more towards smaller building blocks with a clear responsibility (because it hurts to write invariants of classes with more than one responsibility or write pre- and post-conditions for methods with more than one task).

'Debugging'
Contracts can take part in ‘real life’, that means under real runtime conditions, maybe during development and user acceptance test - they take effect under real circumstances while ‘real’ clients (no mocks) and real collaborators (maybe also contracted) interoperate with each other. So contracts also guarding the collaboration of multiple building blocks forcing to fulfill a collective adduced goal due to a specification. having clear sound messages that state the cause of a contract violation, helps locating where the fault lies semantically: it’s very easy to find the reason of a misbehaviour within a specific interaction, pointing directly to it’s origin (if a precondition is violated, than it’s the fault of the client, if an invariant or a post-condition is violated, than it’s the fault of the supplier).

Reuse
For library users (where tests may not be accessible), contracts clearly explain what library classes do and what constraints there are on using them. They provide feedback to someone learning to use other people’s classes: sometimes you only know the interface to operate with - the implementing class is unknown. Having contracts on that interface gives you a clear, sound concept of the limitations and relevant effects in programming against that interface in a proper way.

Open Close Principle Compliance
While tests usually test a single unit, DBC handles inheritance in a broader way, supporting also inheritance of contracts to subclasses and therefore forcing to adhere to the claimed behaviour, stated in contracts of a super class or interface. This goes hand in hand with the Liskov Substitution Principle.

Conclusion
As you might have seen - Design by Contract is contributing some alluring features and 'drivers' when it comes to the specification of the intended behaviour of a component or even a whole system of interacting objects. As seen, contracts also underline the importance of the proper collaboration between clients and suppliers - a feature that’s mostly not in the scope of unit tests.

Those new drivers fit very nicely with the strengths of unit tests (not all mentioned here), making them a perfect fit for a 'specification driven development'.

Until next time,
Mario Gleichmann
http://gleichmann.wordpress.com/

 

Continuous Integration and Build Server – Free Trial

More than a conventional continuous integration (CI) server, Bamboo provides Build Telemetry to help identify and highlight trends, patterns, and linkages across builds — not just focusing on the results of a single build.

30 days free trial (with liberal extension policy - just ask!).

 DZ Top Links
 
 DZone Top Links
 Next section
 Back to top
most clicked this week from dzone.com

dzone

Most-clicked links this week

 
 Popular at JL
 
 Popular at Javalobby
 Next section
 Back to top
A recap of some of the most popular and active Javalobby.org discussions this week.
Multiple return types for Java 7

Of all the personal bug-bears I have with the Java language one of the biggest is the lack of multiple return types. Is Java 7 the time to look at this again?

Full Discussion Posted By: chhum - (79 Replies)

Which look and feel do you use for your swing apps?

The default swing look and feel doesn't rock. But there are very good alternatives available as both open source and commercial. Which one do you use?

Full Discussion Posted By: James Selvakumar - (20 Replies)

Named arguments for method calls

Picking the right arguments in the right order for a method call can be confusing, prone to mistakes, and sometimes cause ambiguity problems. Naming them in the call could improve this.

Full Discussion Posted By: Mike P - (13 Replies)

Generating code without EMF dependencies

Hello everyone!
I would like to generate code from .ecore but without EMF specific
features. Is there an posibility to do this?

Regards,
Luke

Full Discussion Posted By: Lukasz Dywicki - (10 Replies)

Top 5 Java-Related Releases of 2007

The end of the year is near, with top 5 lists appearing everywhere. How about a top 5 list of Java-related software releases? Libraries, frameworks, IDEs, other tools? List your nominations here.

Full Discussion Posted By: Geertjan - (10 Replies)

 White Papers & Announcements
 
 Whitepapers
 Next section
 Back to top
Enterprise Ajax Security for Java EE

Can enterprise application developers deliver Rich Internet Applications using Ajax techniques, but do so in a secure and cost-effective manner? This paper examines some of the fundamental security issues related to client-centric Ajax techniques, and will show how these issues can be overcome using a server-centric approach based on Java EE and ICEfaces.

Download Full White Paper Posted by: Icesoft

 Product Announcements
 Next section
 Back to top
Product and service announcements for Java developers.
Aspose.Newsletter: Free e-newsletter for .NET and Java component programmer

Aspose Newsletter for December 2007 highlights new features by Aspose.Pdf, Aspose.Total for Reporting Services, Aspose.Words, Aspose.Cells, Aspose.Slides and Aspose.BarCode along with a Technical-tip.

Full Announcement & Discussion Posted By: aspose_seo - (0 Replies)

JAlbum 7.4

Version 7.4 has a more workflow oriented user interface, enables you to password protect albums and helps you spread your album to your friends.

Full Announcement & Discussion Posted By: David Ekholm - (0 Replies)

WageTrace 1.0 Released

WageTrace is an application for Salary Grading and developing Job Function Database. WageTrace is an essential software and databank tool for all salary grading organizations

Full Announcement & Discussion Posted By: Dabar Aladejebi - (0 Replies)

Excelsior JET 6.0 Supports Java SE 6, Vista, RHEL 5

The major release brings the Excelsior JET JVM up to date with the latest developments in Java technology and operating systems.

Full Announcement & Discussion Posted By: Dmitry Leskov - (0 Replies)

GigaSpaces Launches Scalability Developer Competition

GigaSpaces announced the OpenSpaces Developer Challenge, which will award $25,000 in prizes to developers who build the most innovative scalable applications or plug-ins for the OpenSpaces Framework.

Full Announcement & Discussion Posted By: Geva Perry - (0 Replies)

iReasoning MIB Browser V5.0 Released

We are pleased to announce the immediate availability of MIB browser version 5.0. Major changes and improvements: * Switch port view * Device Snapshot * Bookmark

Full Announcement & Discussion Posted By: Steve - (0 Replies)

RationalPan Multi Project v3.1.0 - project management software

Stand By Soft has released RationalPlan Multi Project, a strong project management software application developed to assist project managers in creating plans and tracking their progress.

Full Announcement & Discussion Posted By: Lucian Ioan - (0 Replies)

eHour 0.7.1 - Time tracking

eHour is a free web based time tracking tool for consultancy companies and other project based businesses. The primary objective is to keep time tracking as simple and user friendly as possible.

Full Announcement & Discussion Posted By: Thies Edeling - (0 Replies)

BindowsFaces: Ajaxian JSF for Windows L&F

BindowsFaces is a components library that enables programmers create powerful Ajax web applications with a Windows look-and-feel, using Java - through JSF.

Full Announcement & Discussion Posted By: Ran Meriaz - (0 Replies)

More VTD-XML tutorials posted

Two more tutorials forare now available, they do the exactly the same thing as the C tutorial, except rewritten in C# and in Java The C# version: http://downloads.sourceforge.net/vtd-xml/CSharp

Full Announcement & Discussion Posted By: Jimmy Zhang - (0 Replies)

KonaKart v2.2.1.0 - Free Java Shopping Cart - New Release

KonaKart v 2.2.1.0 is a new release of the free java shopping cart software which now includes support for UI skins and more payment gateways and a number of bug fixes.

Full Announcement & Discussion Posted By: Paolo Sidoli - (0 Replies)

released OpenSwing 1.3.7 update

OpenSwing is an open source project that provides a suite of Swing based graphics components, including grid control, gantt control, form control, tree control, tree+grid control and many other input

Full Announcement & Discussion Posted By: mauro carniel - (0 Replies)

Yakkle Instant Collaboration Tool Public Beta

ZenViva has released a public Beta of its Instant Collaboration tool Yakkle. Yakkle offers groups of gmail/jabber users the ability to IM, voice chat, and share desktops (with remote mouse control).

Full Announcement & Discussion Posted By: The ZenViva Guys - (0 Replies)

JOPS 0.5 - Java Open Particle System

JOPS is an open source java library for creating 3d particle effects. It is comprised of a particle library and a SWING editor. The editor uses LWJGL, file loading/saving is done with JIBX.

Full Announcement & Discussion Posted By: Gomes - (0 Replies)

New version of maven-archetypes plugin for Intellij IDEA (1.0.2)

This plugin helps to generate initial java project layout with the help of Maven Archetypes.

Full Announcement & Discussion Posted By: Alexander Shvets - (0 Replies)

JavaRebel 1.0 -- No More Redeploys

JavaRebel eliminates the need for application server redeployment by instantly reloading changes to Java classes.

Full Announcement & Discussion Posted By: Jevgeni Kabanov - (0 Replies)

BundleWorks Application Management Tool Public Beta

Sauers Technologies has released a public beta of BundleWorks. BundleWorks provides a set of tools to simplify and automate the management of applications throughout the development life cycle.

Full Announcement & Discussion Posted By: Ray Sauers - (0 Replies)

J2EE Pattern Oriented Framework (Jt 1.9)

Jt is a pattern oriented framework for the rapid implementation of J2EE applications. Jt implements many well-known design patterns including Data Access Objects (DAO), GoF and J2EE patterns.

Full Announcement & Discussion Posted By: EG - (0 Replies)

Sketsa SVG Editor 5.0 Released

KIYUT just released Sketsa SVG Editor 5.0, a cross platform vector drawing application based on SVG.

Full Announcement & Discussion Posted By: Kiyut - (0 Replies)

Hyperic HQ 3.2 Beta 2

A new beta has been released! See the release notes: http://support.hyperic.com/confluence/display/DOC/HQ+3.2+Release+Notes Download here: http://www.hyperic.com/downloads/dl-hq-beta.html

Full Announcement & Discussion Posted By: John Mark Walker - (0 Replies)

 Your Account
 
 Your Account
 Next section
 Back to top
Manage your account info for this and other Javalobby publications.
Manage your Javalobby membership details

Click on the following links to:


 Contact Info
 Next section
 Back to top
Here's how to reach us, we love to hear from you.
Email us
Send news items to editor@javalobby.org
Send questions, complaints, or suggestions to feedback@javalobby.org
Send advertising inquiries to advertise@javalobby.org
 
Call us
Our number is (919) 678-0300. We'd love to hear from you!

 Legal
 Back to top
The fine print we'd rather avoid completely.
Feel free to redistribute this newsletter in part or in full to your friends.

Javalobby News is a service mark of DZone, Inc.
Copyright ©2001-2007 DZone, Inc.

Thank you for your continued support of Javalobby. If you prefer not to receive the Javalobby weekly newsletter, send an e-mail to ***-jlnews@javalobby.org and please ensure the actual email address to be removed is present.
Javalobby.org, 113 Legault Drive, Cary NC 27513 USA