I read an article about car collision avoidance systems when my programmer wise guy made me think of this concept in an object-oriented way, and it made me wonder if these systems respect the object-oriented programming model.
As the main developer of Java, I transferred this problem to the Java environment and raised a specific question: does calling a public method inside a single class (in a non-statistical context) respect and follow object-oriented?
I mean, take this short hypothetical Car class:
public class Car {
Suppose a thread is responsible for detecting a collision and takes action when it detects a collision, and one of these actions will slow down. Obviously, the brake(...) method is becoming an interesting choice, but doesn't that violate the object-oriented way of doing things? However, this is not only brakes. What if the collision avoidance system in this class used the steering wheel instead to avoid an accident? It seemed strange to me that the car would use its own entrance from an internal point of view ...
More generally, suppose you have a common object that I like to see as a black box. Public methods will be equivalent to leverage on this black box that will control its behavior. Calling a public method in this object would mean that the black box activates its own leverage from its internal mechanism.
I ask because I know that it is legal in Java to do this, and that I have seen public methods that are called in the same class several times in my life, but this legal information does not necessarily mean that this is the right OO way to do this is.
Are public methods used in the same class in an unsteady context, following the rules of object-oriented programming and encapsulation? If not, what would be the right way to do this, or what could be a workaround?
source share