B
Ben Pope
Hi everybody,
I know this is not usually the place for design questions, but I was wondering what some of you more experienced people would do.
Say I have an application that has a C++ & STL core, with a user interface that could be command-line (on topic, I guess) or even .NET/QT/Whatever UI (obviously off-topic, here).
One of the classes in the core stores some data, in a vector. I want to display that information to the user.
Is it preferable to provide an accessor for the private data, e.g.:
std::vector<T> GetData() const {
return storage_;
}
With which the UI can obtain the data - which obviously loses some of my encapsulation, or would it be preferable to make the storage protected, and have the UI component inherit
from the class (probably multiple inheritance required in this case)?
I would prefer not to have any dependency of the UI within the core, so making the UI a friend would be difficult.
Cheers!
Ben
I know this is not usually the place for design questions, but I was wondering what some of you more experienced people would do.
Say I have an application that has a C++ & STL core, with a user interface that could be command-line (on topic, I guess) or even .NET/QT/Whatever UI (obviously off-topic, here).
One of the classes in the core stores some data, in a vector. I want to display that information to the user.
Is it preferable to provide an accessor for the private data, e.g.:
std::vector<T> GetData() const {
return storage_;
}
With which the UI can obtain the data - which obviously loses some of my encapsulation, or would it be preferable to make the storage protected, and have the UI component inherit
from the class (probably multiple inheritance required in this case)?
I would prefer not to have any dependency of the UI within the core, so making the UI a friend would be difficult.
Cheers!
Ben