Re: Programming to an Interface
- From: Robert Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Sun, 28 May 2006 12:59:49 -0500
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 |
.
- References:
- Programming to an Interface
- From: GoogleEyeJoe
- Re: Programming to an Interface
- From: Patrick May
- Re: Programming to an Interface
- From: GoogleEyeJoe
- Re: Programming to an Interface
- From: H. S. Lahman
- Re: Programming to an Interface
- From: Laurent Bossavit
- Re: Programming to an Interface
- From: Sasa
- Re: Programming to an Interface
- From: Laurent Bossavit
- Re: Programming to an Interface
- From: Bernard Notarianni
- Re: Programming to an Interface
- From: Laurent Bossavit
- Re: Programming to an Interface
- From: Bernard Notarianni
- Re: Programming to an Interface
- From: Laurent Bossavit
- Re: Programming to an Interface
- From: Daniel T.
- Programming to an Interface
- Prev by Date: Re: Programming to an Interface
- Next by Date: Re: Programming to an Interface
- Previous by thread: Re: Programming to an Interface
- Next by thread: Re: Programming to an Interface
- Index(es):
Relevant Pages
|
|