I’m trying to figure out the best approach for designing a wrapper class I’m working on.
I have a class, class A
. It has a handful of public methods. I have a second class, class B
, which is used to manage many pointers to instances of A
. A
should be hidden from the user and only accessed through B
, but this isn’t a hard rule could be broken. B
needs to provide the user all the same methods that A
has, for each pointer, by simply wrapping A
‘s functions.
My question is, do I simply wrap A
’s functions? This seems problematic because anytime I add a function to A
, I must write a wrapper function in B
, which seems like redundant code. The other option is to write one single function that returns one of the pointers to A
, so the user could use ->
on it and access all of A
’s methods. In this case, no extra methods need to be written in B
whenever one in A
is added. The issue with this solution is that it exposes A
, which I really don’t want to do, but will if necessary.
Is there a current design pattern that cleanly deals with this? Or some preferred method?
Aucun commentaire:
Enregistrer un commentaire