Design Pattern outline-student

Design Pattern outline-student - Command Pattern Slides...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Command Pattern Slides Builder Pattern Intent Separate the construction of a complex object from its representation so that the same construction process can create different representations. Example Everybody to create a drawing. Here are the instructions for what to put in the drawing: 1) Draw the Sun 2) Draw two large Clouds and six small ones 3) Draw three Mountains 4) Draw a Lake 5) Draw a flock of Birds 6) Draw eight Trees Now, give me your drawing (not really). Would everyones drawings be the same? No. They would all certainly look different. Some might use a computer to create their drawing. Others might use paper and colored pencils. Others might use a canvas and oil paints. Intent (Revisited) Separate the construction of a complex object from its representation so that the same construction process can create different representations . Complex Object: Scenic Drawing Construction Process: My instructions on what objects to put in the picture and where to place them Different Representations: Computer, Paper/colored pencils, Canvas/oil paints, etc. Structure of the Builder Pattern Participants: Product: Complex object we are interested in building Director: Object that drives the construction process (i.e., contains the algorithm for constructing the complex object) Builder: Object that knows to construct the complex object, following the instructions of the Director. Also, returns the complex object after its construction is complete interface SceneBuilder { void addSun(position, size); void addCloud(position, size); void addMountain(position, size); void addLake(position, size); void addBird(position, size); void addTree(position, size); } class ArtDirector { void drawScenicPicture(SceneBuilder builder) { // sun builder.addSun(pos, Medium); // clouds for (int I = 0; I < 2; ++I) builder.addCloud(pos, Large); for (int I = 0; I < 6; ++I) builder.addCloud(pos, Small); // mountains builder.addMountain(pos, Large); builder....
View Full Document

Page1 / 9

Design Pattern outline-student - Command Pattern Slides...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online