Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, tutorials, and more.

21. Prototype

A Prototype is an object that is copied to implement application features. In particular, copying an existing object often provides more flexibility than allocating and initializing new instances from scratch. The Prototype pattern avoids the need to hardcode relationships between objects. For example, Cocoa’s NSMatrix class displays a grid of objects. As rows and columns are added to a matrix, more objects are created as needed to fill in every grid position. NSMatrix wouldn’t be very flexible if it only worked with one kind of object. To provide flexibility, NSMatrix allows you to specify a prototype object that NSMatrix copies as often as necessary to fill in the grid. If you provide a prototype button, you get a grid of buttons. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, interactive tutorials, and more.