4

I am currently working on a problem that has a central controller that is handling inputs and outputs between various modules and maintaining a number of entity classes as these change. When working with getters and setters I can either provide raw values or I can provide one of the entity classes, and I'm curious how this affects coupling. I am working in C++, but I'm curious the way other languages view this.

For example, I can say

object.set_position_and_orientation(double latitude, double longitude, double altitude, double pitch, double roll, double yaw)

or I can say

object.set_position_and_orientation(shared_ptr<object_state> os)

Obviously, sharing this object state is requiring another header in this other module, so I can see it as increasing coupling and complexity; but on the other hand I am defining an interface between these classes through this other entity class.

The answer that we eventually set on is this is a limitation of C++ to have a defined interface, and we settled on including this class that serves as the interface. I'm not satisfied with this answer, but I could not find a definitive "best" way to do it.

1

An object is not a substitute for a bunch of parameters, in other words an object is not (should not be) a record. An object is something with behavior directly tied to the functionality of the application.

So, passing an object, which just has data that will be directly read out on the other side is bad design in object-orientation.

You can only exchange those parameters with an object, if you can find and encapsulate some piece of the application logic in there. That basically means that no one else would be allowed to know the data itself.

That is how object-oriented design works. "Entities" with getters setters are basically the structs we already know from C, that is not object-oriented at all. The problem you're having is not a technical/language one, but a design one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.