EverSpring working shop

To pursue creative ideas based on nature.

统计

留言簿(1)

他山之石

阅读排行榜

评论排行榜

Virtual Constructor

Virtual Constructor:
 
I agree that, actually, the virtual constructor is a morphism of the factory pattern. The Base class define a so-called virtual constructor (in fact, it can't be virtual) which is passed some information about to construct the derived class object. This virtual constructor returns a reference to the new derived class object, which is refereced or pointed by the private data memeber of the base class.
 
The user of the base class object passes to the virtual constructor of the base class with the information which is used to construct the derived class in the virtual contstructor. Then the user just invokes the desired application through interface of the base class, because the actual operation for these application is implemented by below code:
 
base_class.operate()
{
  base_class::ptr_to_derived_obj.operate()
}
 
Alex Zhang
 

posted on 2008-01-05 23:55 everspring79 阅读(525) 评论(0)  编辑 收藏 引用 所属分类: Notes


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理