User:Ccw: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Proposed solution to issue 4377 updated) |
||
| Line 21: | Line 21: | ||
{ | { | ||
public: | public: | ||
CClientColModel ( | CClientColModel ( CClientManager* pManager, ElementID ID ); | ||
~CClientColModel ( void ); | ~CClientColModel ( void ); | ||
... | ... | ||
| Line 68: | Line 68: | ||
CClientColModel ( void ) {} | CClientColModel ( void ) {} | ||
~CClientColModel ( void ) {} | ~CClientColModel ( void ) {} | ||
void PostConstruct ( | void PostConstruct ( CClientManager* pManager, ElementID ID ); | ||
virtual void PreDestroy ( void ); | virtual void PreDestroy ( void ); | ||
public: | public: | ||
static CClientColModel* NewCClientColModel ( | static CClientColModel* NewCClientColModel ( CClientManager* pManager, ElementID ID ); | ||
... | ... | ||
void CClientColModel::PostConstruct ( | void CClientColModel::PostConstruct ( CClientManager* pManager, ElementID ID ) | ||
{ | { | ||
CClientEntity::PostConstruct ( ID ); | CClientEntity::PostConstruct ( ID ); | ||
| Line 87: | Line 87: | ||
} | } | ||
CClientColModel* CClientColModel::NewCClientColModel ( | CClientColModel* CClientColModel::NewCClientColModel ( CClientManager* pManager, ElementID ID ) | ||
{ | { | ||
CClientColModel* pElement = new CClientColModel (); | CClientColModel* pElement = new CClientColModel (); | ||
pElement->PostConstruct ( | pElement->PostConstruct ( pManager, ID ) | ||
return pElement; | return pElement; | ||
} | } | ||
Revision as of 15:05, 1 June 2009
Some class constructors and destructors are too complex
Proposed solution to [issue http://bugs.mtasa.com/view.php?id=4377]
Move code out of constructors and destructors into functions that are called post-construction and pre-destruction respectively.
Example of solution when applied to CClientEntity and CClientColModel:
Current base and concrete class declaration:
class CClientEntity
{
public:
CClientEntity ( ElementID ID );
virtual ~CClientEntity ( void );
...
class CClientColModel: public CClientEntity
{
public:
CClientColModel ( CClientManager* pManager, ElementID ID );
~CClientColModel ( void );
...
Proposed base class declaration and definition:
class CClientEntity
{
protected:
CClientEntity ( void ) {}
~CClientEntity ( void ) {}
void PostConstruct ( ElementID ID );
virtual void PreDestroy ( void );
public:
void Delete ( void );
...
void CClientEntity::PostConstruct ( ElementID ID )
{
// Code from CClientEntity constructor moved here
}
void CClientEntity::PreDestroy ()
{
// Code from CClientEntity destructor moved here
}
void CClientEntity::Delete ( void )
{
PreDestroy ();
delete this;
}
Proposed concrete class declaration and definition:
class CClientColModel: public CClientEntity
{
protected:
CClientColModel ( void ) {}
~CClientColModel ( void ) {}
void PostConstruct ( CClientManager* pManager, ElementID ID );
virtual void PreDestroy ( void );
public:
static CClientColModel* NewCClientColModel ( CClientManager* pManager, ElementID ID );
...
void CClientColModel::PostConstruct ( CClientManager* pManager, ElementID ID )
{
CClientEntity::PostConstruct ( ID );
// Code from CClientColModel constructor moved here
}
void CClientColModel::PreDestroy ()
{
// Code from CClientColModel destructor moved here
__super::PreDestroy ();
}
CClientColModel* CClientColModel::NewCClientColModel ( CClientManager* pManager, ElementID ID )
{
CClientColModel* pElement = new CClientColModel ();
pElement->PostConstruct ( pManager, ID )
return pElement;
}
Other changes required
Any occurrence of
new CClientColModel ( pStreamer, ID ); delete pElement;
should be replaced with
CClientColModel::NewCClientColModel ( pStreamer, ID ); pElement->Delete ();
