OO Design and Polymorphism Design: Assignment

Added on - 16 Sep 2019

  • 16

    Pages

  • 2346

    Words

  • 203

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 4 of 16 pages
CEWP559, FALL 2016Assignment 3Due: December 6, 2016TASK 1(2 5 M ARK S)This assignment will give you practice with the following concepts;OO Design; polymorphismDesign patterns; Factory, Iterator, Composition (optional).TestsYou will design a program that uses composition, polymorphism, iterators and factories to display multiple objects on a canvas.The final image will look like the following.What should be submitted:1.A zip file with all the classes, files, xml file. (Ready to run).2.Place a generated BMP image into the zip file (if you can generate the image).3.Results of your test method run.4.Results of your graphic test run.S T E P 1 | P RO J E CT L A Y O UTPage1of16
Directory Structure;FilenameFunction(s)Canvas.phpThis is the collection, it contains the list of objects.MainDriver.phpThis runs the project. It simply displays a graphic of a house at the end. (See appendix).shape_input_file.xmlXML defining all the shapes.shape_input_file_TEST.xmlXML for testing the “TestGraphics” file. See appendix.ShapeFactory.phpGenerates the shapes as we read the XML file.Write a simple factory to return the shapes you need.ShapeIterator.phpProvides an interator to process the collection in Canvas.You can re-use the method shown in class (Iterator for books).TestDriverThe tests (See appendix)TestGraphicsThe graphic tests (See appendix)Method structure;Canvas.phpMethod NameDetailsConstructorThis contains most of the code for this assignment!1)Define an object of the factory, to get shapes.2)Read the XML file for the background color, sizes, and issue a “imagefill” command to take care of it.Reminder, to get the color use the allocatecolor method like this: $this->allocateColor($back_color).3)When creating the image here, using imagecreatetruecolor, remember that the values for width andheight might need to be casted to integer for it to work. Eg: $this->im = imagecreatetruecolor((int)$back_width, (int)$back_height);4)Do a foreach on all the shapes in the XML, for each shape get the shape from the factory, fill in the values,and then add it to the canvas using the “addShape” method.Note: When reading in the XML, example, the children() of shapes, you can get the name of the current elementsPage2of16
by calling the function getName().Eg: If you have this....<drawing><background><colour>color_green</colour><width>240</width><height>150</height></background><shapes><rectangle>...</rectangle><ellipse>...</ellipse>Using getName will return “rectangle” and “ellipse” if called in a forEach loop.allocateColor($color)Returns an image color object when requested, basically this is similar to a factory.For example;switch ($color) {case "color_brown":return imagecolorallocate($this->im, 165, 42, 42);case "color_lightgray":return imagecolorallocate($this->im, 211, 211, 211);The colors are:color_brownPage3of16
( 165,42,42)color_lightgray( 211, 211, 211)color_lightblue( 135,206,250)color_brightyellow( 255,255,0)color_white( 255, 255, 255)color_darkbrown( 155, 32,32)color_darkgray( 50,50,50)color_green( 50, 200, 50)color_blue( 40, 40, 245)addShape(Shape $shapeIn)See the iterator example for books shown in class. This method is contained there in the collection object.Page4of16
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document