14.1. Problem and Solution
As applications become more advanced, the core objects seem to follow suit. While it still may be a fully modular approach to creating these standard objects, the path to build a proper object has perhaps grown tenfold. Other times the code base is not as perfectly streamlined as the programmer would wish. Either way, some objects start to become expensive to create. The extra time needed to construct this object or the amount of memory it consumes is the expense that should try to be avoided. A good way to recognize this is that it seems like it might be simpler to create a new type of object that mimics the behaviors of a core object without all of the complexity. When it starts becoming obvious that the cost for creating these objects is becoming prohibitive, there are two ways to move forward. The first is refactoring. As alluded to earlier, there might become a point where refactoring is no longer practical or even possible. The other path to investigate involves modifying the objects so that they can be duplicated using the Prototype Design Pattern.
The Prototype Design Pattern maps out a way to reduce the expense of creating complicated objects. It does this not by removing the intricacies of the object itself but by creating an interface to preserve those properties through duplication. The Prototype Design Pattern is useful, especially when complex objects will not change their state throughout the code stream. That is to say, the initial state ...
Get Professional PHP Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.