C
Crash
2 Questions, but first Consider this:
I'm looking at a C++ class (patterned using the Singleton Design
Pattern). It has some public and private operations. It runs quite
happily seving the time and date to everybody. The private operations
setTheTime() and setTheDate() I require to be called/influenced
externally. For instance a class SubsysA has the right to call
setTheTime() only, and class SubsysB has the right to setTheDate()
only.
Questions:
Did I break the rules of C++ ?
What would you call this interface design pattern?
Here's how I did it.
//Note: constructor/destructor/singleton
// stuff purposely left out for brievity
Example:
class TimeDateManager
{
public:
TimeDateManager* getInstance()
timeStruct getTheTime();
dateStruct getTheDate();
private:
void setTheTime(const timeStruct& the_time);
void setTheDate(const dateStruct& the_date);
timeStruct theTime;
dateStruct theDate;
}
....And...
class SubsysA
{ //needs the right to set the time during its execution
void execute();
}
class SubsysB
{ //needs the right to set the date during its execution
void execute();
}
So, I created 2 classes I call "The Privatized Polymorphic Interface"
class PPI_A
{ friend class SubsysA;
private:
//create a virtual function same name and
//arguments as in the TimeDateManager
virtual void setTheTime(const timeStruct& the_time);
}
class PPI_B
{ friend class SubsysB;
private:
//create a virtual function same name and
//arguments as in the TimeDateManager
virtual void setTheDatee(const dateStruct& the_date);
}
Make the TimeDateManager inherit both these PPI's
class TimeDateManager : public class PPI_A, public class PPI_B
{ ...
}
Now the SubsysA has the right to do upcast in its execute()
( (PPI_A*) TimeDateMngr::getInstance()
)->set_theTime(new_time_data);
Now the SubsysB has the right to do this in its execute()
( (PPI_B*) TimeDateMngr::getInstance()
)->set_theDate(new_date_data);
Wow! It works. It meets my requirements to. Quick and clean. The PPI
parent, by v-table-polymorphism, saw its child's private operation in
the TimeDateManager! I had to predeclare some classes so circular
dependecy in the #include didn't happen.
What would you all call this type of interface?
I'm looking at a C++ class (patterned using the Singleton Design
Pattern). It has some public and private operations. It runs quite
happily seving the time and date to everybody. The private operations
setTheTime() and setTheDate() I require to be called/influenced
externally. For instance a class SubsysA has the right to call
setTheTime() only, and class SubsysB has the right to setTheDate()
only.
Questions:
Did I break the rules of C++ ?
What would you call this interface design pattern?
Here's how I did it.
//Note: constructor/destructor/singleton
// stuff purposely left out for brievity
Example:
class TimeDateManager
{
public:
TimeDateManager* getInstance()
timeStruct getTheTime();
dateStruct getTheDate();
private:
void setTheTime(const timeStruct& the_time);
void setTheDate(const dateStruct& the_date);
timeStruct theTime;
dateStruct theDate;
}
....And...
class SubsysA
{ //needs the right to set the time during its execution
void execute();
}
class SubsysB
{ //needs the right to set the date during its execution
void execute();
}
So, I created 2 classes I call "The Privatized Polymorphic Interface"
class PPI_A
{ friend class SubsysA;
private:
//create a virtual function same name and
//arguments as in the TimeDateManager
virtual void setTheTime(const timeStruct& the_time);
}
class PPI_B
{ friend class SubsysB;
private:
//create a virtual function same name and
//arguments as in the TimeDateManager
virtual void setTheDatee(const dateStruct& the_date);
}
Make the TimeDateManager inherit both these PPI's
class TimeDateManager : public class PPI_A, public class PPI_B
{ ...
}
Now the SubsysA has the right to do upcast in its execute()
( (PPI_A*) TimeDateMngr::getInstance()
)->set_theTime(new_time_data);
Now the SubsysB has the right to do this in its execute()
( (PPI_B*) TimeDateMngr::getInstance()
)->set_theDate(new_date_data);
Wow! It works. It meets my requirements to. Quick and clean. The PPI
parent, by v-table-polymorphism, saw its child's private operation in
the TimeDateManager! I had to predeclare some classes so circular
dependecy in the #include didn't happen.
What would you all call this type of interface?