# Representing/Modelling fields and methods in the context of programming as automata

I am trying to represent/model fields and methods in the context of programming as automata. For instance, let's say that I have field1 with state equal to 2, field2 with state equal to 3, and method1 being the calculation field2 $$=$$ field1 $$\times$$ 2 $$+$$ field2 $$\times$$ 3. If I represent field1 as one automaton and field2 as another automaton, field1 would first change its state to $$2 \times 2 = 4$$ and then field2 would change its state to $$3 \times 3 = 9$$. But it isn't clear to me how one would then represent the interaction between these two automatons to make field2 state equal to $$4 + 9 = 13$$ (since the automaton representing field2 would need to retrieve the state value of the automaton representing field1), and nor is it clear to me how one would have the "transience"/"temporary" aspect, since field1 would then have to revert back to state equal to $$2$$ (since the computation with regards to this field/automaton is temporary and not permanent).

I suspect that this stuff has already been figured out, but I'm a fresh grad student, so I'm not really aware of this stuff.

One standard way to model this is to have one automaton per object. The state space of that automaton is the value of all of the fields of that object. Calling a method on object $$O$$ corresponds to message-passing: sending a message to that object $$O$$ with the name of the method and any arguments. A system containing multiple objects is obtained by parallel composition of the automata (one automaton per object).
In your case, the state space is either infinite or very large depending on whether you are using unbounded integers, and it makes sense to use parametrised messages. For example, you could have a message $$current(n)$$ which field2 uses to communicate its current value. The automata would then have transitions like
$$k \xrightarrow[]{current(n)} 3k+2n$$ for all $$k,n$$ in field1
$$n \xrightarrow[]{current(n)} n$$ for all $$n$$ in field2
where we use the values $$k, n\in \mathbb{Z}$$ as the states for each automaton. The automata synchronise on these messages so e.g. field2 can only use a $$current(4)$$ transition when field1 has the value $$4$$ (so that the message is enabled).