Re: Object Ptr as Handle ?
Hi all,
Thanks for your comments. A few more details on the actual design ...
The code goes something like follows:
typedef PVOID HANDLE;
class Base {
public:
virtual int Action1 (void) {
return REQ_NOT_SUPP;
}
virtual int Action2 (void) {
return REQ_NOT_SUPP;
}
};
class Derived1: public Base {
public:
int Action1 (void) {
DoSomething ();
}
};
class Derived2 : public Base {
public:
int Action2 (void) {
DoSomethingelse ();
}
};
class Mgr {
private:
Base* m_pManagedObjects [MAX_OBJ];
public:
CreateAndAddObject (create_info, HANDLE *phObj)
{
Base *pBase;
if (create_info)
pBase = new Derived1 ();
else
pBase = new Derived2 ();
*phObj = (HANDLE) pBase;
pManagedObjects [free_loc] = pBase;
}
ManipulateObjects (HANDLE hObj) {
Base *pObj = (Base *) hObj;
CheckIfInManagedList ();
pObj->Action1 ();
}
};
My Mgr is a singleton and it manages all objects that are derived from
Base. I got comments that this method violates OOPS concepts and that
passing on the object pointer as a handle is not a good idea. The
alternate method I could think was to keep a handle map table in Mgr.
I'm working on embedded systems and I do not wish to waste memory on
such a table if the existing solution is not a recipe for disaster.
I'm not sure which OOPS principle is in violation here as well. As
illustrated above, most functions in my base class are virtual and says
"request_not_supported". My derived classes override only the functions
they support. In net effect, my base class always has the sum of all
the I/Fs of my derived classes.
Kindly send in your suggestions.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]