Hi, I had a class Display with 2 utility functions getDate and getTime like below.
class Display
{
public:
void getDate(char *pDate); //Utility functions for converting to custom format
void getTime(char *pTime);
};
Later, In other class called Retriever also, i needed the same Utility functions getDate and getTime. I do not want to make getDate
and getTime
functions global(Or C like functions), to avoid accidental usage of these functions(which are specific to these 2 classes). Even wrapping them in namespace won't prevent accidental usage.
Display and Retriever are dissimilar classes. Can't use inheritance between them. Can't use Composition and aggregation as the lifetime of the objects of those classes will be different. They do not exist together(at same time).
Is there any good way of moving Utility functions out of Display and use them in both classes Display and Retriever ? Is it good to put getDate and getTime in seperate class called Utilities and use object of it in classes Display and Retriever ?