Re: Programming to an Interface



On 2006-05-15 16:47:44 -0500, "Daniel T." <postmaster@xxxxxxxxxxx> said:

def debitAccount amount
transaction = makeTransaction()
transaction.execute(this) {balance -= amount}
end

That is, the mechanics of persisting changes to an object and wrapping the business logic in a transaction would be hidden at the next level down. You don't care how persistence or transactions are implemented, only that you can rely on both.

Depending on where/how this "makeTransation()" is implemented, I would say the above is more programming to an implementation than the original code. Now to Mock the transaction object, one has to change the implementation of the make function.

One man's interface is another man's implementation. For code to be semantically valid there must be some implied implementation. For example, in the above we must assume that Transaction.execute takes the object being modified and saves it to the DB while locking out any concurrent changes.

Still, the code above says nothing about RDB, tables, rows, or anything else at all about the persistence mechanism. The fact that we have a transaction is not an artifact of persistence so much as it is an artifact of concurrency that protects us from concurrent update. So the author has successfully avoided the implementation of the RDB and programmed to the interface of only the Account object, and the Transaction object.


--
Robert C. Martin (Uncle Bob)  | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc.            | blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716                  |



.



Relevant Pages

  • Re: chooses not to generate code at all
    ... > The point is that one does not need persistence to do ... > transaction processing. ... That's why you would still need a DBMS event if you don't need ... Other simpler tools can handle persistence in business transaction ...
    (comp.object)
  • Re: CLOS and databases
    ... you get a transaction for every write no ... It also depends on whether you want to be able to rollback object changes. ... (setf object (make-instance 'persistent-user-class)) ... These are some of the fun problems persistence framework guys get to fight ...
    (comp.lang.lisp)
  • Re: Database transactions and data-state flags
    ... MTS would roll the update for both the Invoice and LineItems into one ... Transaction. ... Not sure what you mean by objects handling its own persistence. ...
    (microsoft.public.vb.general.discussion)
  • Re: static classes & threading
    ... Bruce Wood wrote: ... In your case, if you have one shared transaction object, you could ... time, they will both discover that there is no transaction object available, and they will both create a new Transaction, the later one clobbering the Tranasaction created by the earlier one. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: static classes & threading
    ... static state or the object's state. ... In your case, if you have one shared transaction object, you could ...
    (microsoft.public.dotnet.languages.csharp)