0

note: This is of couse about software-architecture/design-principles, but as no architecture is completely detached from its language, please note that the language i am using is C++.

I am using an API, with a debug-layer that lets you give names to API-specific objects, so that readable debug-output is generated from within the API.

Assume that i want to give the name "ANiceObject" to an object A

Because that object is relatively "low-level", it is part of an abstraction B in my code. But to name it, i need access to the object itself. I see the following options:

  • provide getter inside B to access A (breaks encapsulation)
  • provide interface in B to name A (B shouldn't have that responsibility)

Apart from this problem, i also want this debug-logic to be as separate as possible from the production-logic.

Has anyone some guidance, or ideas on how to achieve the naming of A for debug-purposes without breaking my architecture, and cluttering my code?

7
  • Are you naming an object or a class? Commented Jun 25, 2020 at 17:29
  • @candied_orange an object, or rather multiple objects. In reality, there will be multiple instantiations of B, each with a differently named object A inside. Note that, by naming, i refer to letting the API give a name to A, which is an opaque handle to me. I am not referring to giving a string-member-variable or sth. like that. Let me know if things are unclear in my question, and i will edit to clarify. Commented Jun 25, 2020 at 17:37
  • so I take it you mean you want a reference or a pointer to this object. Commented Jun 25, 2020 at 17:48
  • @candied_orange of course i need some access to the object in order to name it. As noted i neither like the idea of providing a getter, nor the idea of letting the container-class handle the naming itself though. Commented Jun 25, 2020 at 18:29
  • Well the only other idea would be to build A yourself and pass it to B. Then you just have to remember what you named it before. The fancy name for that idea is dependency injection. Commented Jun 25, 2020 at 18:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.