No, this does not violate the OOP principle.
An important example is an object whose behavior depends on whether the connection is established or not (for example, the doNetworkStuff() function depends on openConnection() ).
In Java, there is even a typestate checker that performs such checks (whether Duck already Quack() ) compile time. I often have dependencies such as prerequisites for interfaces, and I use the redirect class, whose sole purpose is to log and check the state of the object to which it forwards, i.e. A protocol whose functions were called on the object, and an exception exception (for example, InvalidStateException) when the preconditions are not met.
The design pattern that handles this is state : it allows an object to change its behavior when its internal state changes. It looks like the object will change its class. The model book from Gang of Four also uses the above example of a steady network connection.
Davefar
source share