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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access