I'm a newbie for design pattern.I feel I missing some essential pieces in understanding Builder Pattern. what the object representation exactly means in this definition?
THE BUILDER PATTERN: Separates the construction of a complex object from its representation so that the same construction process can create different representations.
Is it means the object's internal struct(instance variable and member function)? I has look for on Internet but still confuse it,any help is appreciated!
According to the GoF, the Builder pattern is a creational pattern, therefore, it solves a specific problem when you need to create object.
The need for the Builder pattern arises when you need to create a complex object with many dependencies and it is impossible or impracticable to obtain all this dependencies at the same time.
Let's take as example a car assembly line. Not all cars are equal, albite all of them have similar structure (such as a frame, wheels, steering wheel, brakes, lights), they may differ in their optionals, such as digital air conditioning, solar roof, parking camera and so on.
This assembly line should be flexible enough to be able to build cars with any configuration the customer wants with minimum setting.
Lets imagine that the assembler machine recieves the blueprint of the new car it must assemble and then follows that spec.
Bringing this to our object-oriented software engineering world, we might have:
So, answering your question:
Yes, it refers to internal structures. Normally, an instance variable, since in PHP it is not a good practice to change a class contract by adding methods to it.
While my example above might seem dumb, I deliberately made it that way for the sake of simplicity.
But as a mental exercise, think what would happen if some of the components had their own dependencies that cannot be obtained right the way. Then you would be able to delay the
CarImpl
object until you can fullfil all its component dependencies.