Applications of DBC

From: Daniel Parker (danielaparker_at_spam?nothanks.windupbird.com)
Date: 12/19/03

  • Next message: Isaac Gouy: "Re: Test Driven Development Sample"
    Date: Fri, 19 Dec 2003 00:08:41 -0500
    
    

    I'm a little new to thinking in terms of DBC, so I'd appreciate any
    feedback.

    I've tended to rely on unit test cases for validation, but recently there
    arose an issue with one of my apps where it appeared that a payment in a
    recovery situation had been sent twice. It turned out that this was due to
    an error introduced by manual intervention, not the app. But when I was
    studying what could have happened, the fact that I had a lot of unit tests
    that all passed only suggested that the app was highly reliable, it didn't
    rule out the _possibility_ that the problem was due to the app, or mean that
    I could go home yet. Reasoning about the app's event model gave more
    comfort, because the model suggested that the problem couldn't happen, and
    visual inspection of the code seemed to indicate that the code was in
    conformance with the model. But then I started to become aware that
    conformance really implied that the code satisfy a fair number of
    invariants. And it would have been even more comforting to know with
    certainty that they had all been satisfied at the time the problem with the
    duplicate payment occurred.

    Now, suppose I have a method that does something like this (my real world
    counterpart is less trivial but analogous)

    Start a database transaction
    Update a batch header status for a given batch id.
    Update the status in the database of all messages in a certain stage of
    processing that are associated with the batch
    Perform a rollback if any exception is thrown, otherwise commit all the
    changes.

    Now, suppose I want to introduce some invariants. After the batch header is
    updated, the number of rows updated must be one. After the update statement
    is performed on the messages, the number of rows updated must equal the
    number of messages belonging to the batch.

    Now, I could place asserts into the body of the code to inforce these
    invariants There are already a fair number of asserts like that strewn
    through the code, although in this app these exceptions need to be handled,
    the discards logged, users notified, but processing of the next batch
    continued.

    But adding asserts doesn't sound enough like DBC. Presumably we could start
    by breaking up the method into sub methods, and defining contracts for them.
    That would add a lot of methods to a service class. I suppose we could
    encapsulate the sub method and methods expressing pre and post conditions in
    a (Java) inner class. Now the code would start to look a little different
    than it would in a procedural model, and I'm not sure that's good or adds to
    readability.

    I would be interested if somebody who is experienced in DBC could comment on
    how they would structure something like this. Everything here is at a level
    of granularity that is only accessible within the module, within a
    transaction actually, and not outside.

    Regards,
    Daniel Parker


  • Next message: Isaac Gouy: "Re: Test Driven Development Sample"

    Relevant Pages

    • Re: Applications of DBC
      ... >Update a batch header status for a given batch id. ... To do DbC in Java you can use package access rights to separate the DbC ... Using transaction rollbacks is an example of the latter. ...
      (comp.object)
    • Re: Is VMS losing the Financial Sector, also?
      ... instances are reduced by placing the App serveron the same server as ... Depending on how beefy your server is, and how parsimonious the CFO is. ... Since it's being rewritten in Oracle and hosted on a SAN, moving the batch cycle to another machine shouldn't be "that much" of a chore if the database+batch machine gets burdened. ... A dozen or so of the lead developers have been with the project 8 years or more (in that time, 2 of them have had the time to segue from "Indian consultants wanting to return in 5 years" to married- ...
      (comp.os.vms)
    • Re: Problem when executing application from batch file
      ... If PrevInstance was not returning the correct information, ... batch file would translate into 4 running instances of my app). ... >> maybe executing 4 times, but your the logic that checks for PrevInstance ...
      (microsoft.public.vb.general.discussion)
    • Re: Batch file to delete files by date (Or VBScript?)
      ... microsoft.public.win2000.cmdprompt.admin:>I have pretty much decided I am going to consolidate several operations and>modify a VB app I already have written for a different purpose. ... I found the problem with developing scripted batch operations using VB/VBS is their lack of interactivity and difficulty in debugging. ... 4DOS, which also knows about Date Ranges, is free. ... Pure CMD syntax for this operation would be a lot more complicated. ...
      (microsoft.public.win2000.cmdprompt.admin)
    • Re: Problem when executing application from batch file
      ... I think that your app maybe ... If you see 4 copies of the MsgBox, then the batch file is executing as ... >> Apparently this is only supported in XP and most likely Windows 2000. ...
      (microsoft.public.vb.general.discussion)

    Loading