One (perhaps obvious) thing I’ve practiced over the years is to write code where every variable and method has the most private access control possible. As I iterate over the code and refactor pieces, I keep trying to limit access to data. In effect, limiting access helps with encapsulation.

Once I’ve iterated over the code several times, I find that the public methods usually leads to a good API. With some refinement, the public methods become public interfaces/protocols which eventually other modules consume.