Template method pattern: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 3:
A template method defines the skeleton of an algorithm in terms of abstract operations which subclasses override to provide concrete behaviour.
 
'''Example:'''
Define the skeleton for Data-structure algorithms. Each kind of Data-structure algorithm has few common operations and few specific. The Data-structure template class can provide skeleton for each newly added Data-Structure Class.
 
class CDatastructure_Template
{
//Common operations: Algorithm Template
void virtual CleanAll()=0;
void virtual AddNode(Node *node)=0;
void virtual DeleteNode(Node *node)=0;
long virtual GetNumElements()=0;
Node* virtual GetTopNode()=0;
Node* virtual GetNextNode(Node *CurrentNode)=0;
};
 
class CLinkList_ConcTemplate : public Datastructure_Template;
class CQueue_ConcTemplate : public Datastructure_Template;
class CArray_ConcTemplate : public Datastructure_Template;
class CTree_ConcTemplate : public Datastructure_Template;
 
If we need to introduce a new data-structure class double-link list then we can drive it from CLinkList_ConcTemplate to get the algorithm template and can modify operations.
Akash Gupta(mrakash@hotmail.com)
--[[User:203.90.124.178|203.90.124.178]] 11:44, 22 Jun 2004 (UTC)
{{msg:stub}}