TLDR: Should object composition be favored over de-encapsulation? Could you please recommend some good examples of interfaced objects and object composition?
_
I think a good example of a procedural interface is the input/output read/write system routines. They are self contained, versatile, and I am sure you could came up with other advantages of such procedural design. So I started implementing io routines. Once written, I realized many redundant code could benefit from a wrapper to avoid such redundancy. That is why I wrote this class:
https://github.com/cpicanco/stimulus_control/blob/master/src/units/loggers.datafile.pasIt is very simple. Open, Write, Close with some utilities. In this program, one class needs to Open/Close/Write, but all other classes needs only to write. My solution was to remove the encapsulation of this public procedure for all other classes by means of a property.
https://github.com/cpicanco/stimulus_control/blob/master/src/units/session.blocs.pas#L113https://github.com/cpicanco/stimulus_control/blob/master/src/units/session.configuration.pas#L26So what?
Now I am learning about interfaced objects and realized that this problem could be solved more intuitively using them. For example, using object composition instead of removing (from outside) the encapsulation of an existing class; i.e., by composing other classes using interfaces. Do you agree?
P.S.: Of course, everything is working, and the point here is to be ready for future problems, not changing what is already working.