Is there a standard pattern in OOP to kind of "atomically" update a pair of objects, like a pair of bank accounts on a transaction?

I would like to have somehow a single public method exposed that does it all at once, but can only come up with ways of doing it by making *two* calls of public methods to update objects separately.

I am currently experimenting with *Racket*, but i would appreciate examples in any language, or a description of a standard pattern.

---

Here is an example of what i have experimented in *Ruby* (with which i am more comfortable than with *Racket*). I am not concerned with locking here, just with class interface.

```rb
class Account
  def initialize(total)
    @total = total
  end

  def total
    @total
  end

  def transfer_to(another, sum:)
    change_total_by(-sum)
    another.change_total_by(sum)
  end

  protected

    def change_total_by(sum)
      @total += sum
    end

end

a = Account.new(10)
b = Account.new(20)
a.transfer_to(b, sum: 5)
print "New a.total = #{ a.total },\nnew b.total = #{ b.total }"

```

This works using `protected` instead of `private`.