Questions about the Prototype Pattern

前端 未结 3 1300
灰色年华
灰色年华 2020-12-12 13:40

I am learning about the different design patterns and I have a strong feeling I am missing an essential piece (or pieces) in understanding this particular pattern.

I

3条回答
  •  悲哀的现实
    2020-12-12 14:07

    The gain in efficiency of using a prototype is questionable in my mind. There will be no efficiency gain because in most languages the clone method itself executes a call to new in order to construct a new object instance of itself.

    The only benefit that I see in using the prototype pattern is one of convenience, you know that clone will give you an exact copy of the object which frees you from having to set the attributes of the new object to the same values yourself and possibly struggling with deep copy.

提交回复
热议问题