Template method pattern

This is an old revision of this page, as edited by 203.90.124.178 (talk) at 11:57, 22 June 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The template method pattern is a software design pattern used for computer programming.

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--203.90.124.178 11:44, 22 Jun 2004 (UTC)