1 / 27

Comp 110/401 Composite Annotations

Comp 110/401 Composite Annotations. Instructor: Prasun Dewan. Prerequisite. Composite Objects Shapes. Interpreted How?. public interface RectangleWithPoint { public int getX (); public int getY (); public void getWidth (); public void getHeight ();

trynt
Download Presentation

Comp 110/401 Composite Annotations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Comp 110/401Composite Annotations Instructor: PrasunDewan

  2. Prerequisite • Composite Objects Shapes

  3. Interpreted How? publicinterfaceRectangleWithPoint { publicintgetX(); publicintgetY(); publicvoidgetWidth(); publicvoidgetHeight(); public Point getPoint(); } Bad programming as code for defining Rectangle cannot be used in situations where rectangle without point is needed Object interpreted as either an atomic rectangle or an atomic point depending on whether Point or Rectangle in the name gets precedence

  4. Reusable Design publicinterface Rectangle { publicintgetX(); publicintgetY(); publicvoidgetWidth(); publicvoidgetHeight(); } publicinterfaceRectangleWithPoint { public Rectangle getRectangle(); public Point getPoint(); }

  5. ObjectEditor Graphics Rules publicinterfaceShuttleLocation { publicFancyCartesianPlanegetCartesianPlane(); publicImageLabelgetShuttleLabel(); publicintgetShuttleX(); publicvoidsetShuttleX(intnewVal); publicintgetShuttleY(); publicvoidsetShuttleY(intnewVal); } publicinterfaceNotAPoint { publicFancyCartesianPlane getCartesianPlane(); publicImageLabelgetShuttleLabel(); publicintgetX(); publicvoidsetX(intnewVal); publicintgetY(); publicvoidsetY(intnewVal); public Point getLocation(); } Type interpreted as a Point as its name contains “Point” and has X and Y Properties

  6. IS_ATOMIC_SHAPE Class Annotation importutil.annotations.IsAtomicShape; @IsAtomicShape(false) //same as AShuttleLocation except interface name publicclassAShuttleLocationImplementingABadlyNamedInterfaceimplementsNotAPoint { Annotation is like a comment except it is typed and available at runtime IsAtomicShape(false) before class name says do not interpret the class as an atomic shape (it can be a composition)

  7. ShuttleLocation Alternatives publicinterfaceShuttleLocation { publicFancyCartesianPlanegetCartesianPlane(); publicImageLabelgetShuttleLabel(); publicintgetShuttleX(); publicvoidsetShuttleX(intnewVal); publicintgetShuttleY(); publicvoidsetShuttleY(intnewVal); } publicinterfaceShuttleLocationWithPoint { publicFancyCartesianPlanegetCartesianPlane(); publicImageLabelgetShuttleLabel(); publicPoint getShuttleLocation(); publicvoidsetShuttleLocation(Point newVal); }

  8. Point Property publicclassAShuttleLocationWithPointimplementsShuttleLocationWithPoint { publicPoint getShuttleLocation() { returnshuttleLocation; } … } Does not have X and Y properties, so not a point But location displayed as a point shape

  9. IS_ATOMIC_SHAPE Annotation of Class Getter importutil.annotations.IsAtomicShape; publicclassAShuttleLocationWithPointimplementsShuttleLocationWithPoint { @IsAtomicShape(false) publicPoint getShuttleLocation() { returnshuttleLocation; } … } IsAtomicShape(false) before getter of a property means property not displayed as an atomic shape ShuttleLocation is not a textual property displayed in main panel What if we do not want it in main panel either?

  10. Visible Annotation of Class Getter importutil.annotations.Visible; publicclassAShuttleLocationWithPointimplementsShuttleLocationWithPoint { @Visible(false) publicPoint getShuttleLocation() { returnshuttleLocation; } … } Visible(false) before getter of a property means property not displayed at all

  11. Automatic Label Pattern publicclassAShuttleimplementsSpecificImageLabel { … }

  12. Not Following Automating Label Pattern publicclassAShuttleimplements Shuttle { … }

  13. Explicit Pattern Specification importutil.annotations.StructurePattern; importutil.annotations.StructurePatternNames; @StructurePattern(StructurePatternNames.LABEL_PATTERN) publicclassAShuttleimplements Shuttle{ … } Structure(<PatternName>) before class asserts that the class is following the pattern. ObjectEditor ignores class name and gives warnings if methods do not follow the pattern

  14. Explicit Pattern Specification importutil.annotations.StructurePattern; importutil.annotations.StructurePatternNames; @StructurePattern(StructurePatternNames.LINE_PATTERN) publicclassAShuttleimplements Shuttle{ … }

  15. Explicit Pattern Specification publicclassAShuttleLocationimplementsShuttleLocation { … }

  16. Explicit Pattern Specification importutil.annotations.StructurePattern; importutil.annotations.StructurePatternNames; @StructurePattern(StructurePatternNames.LINE_PATTERN) publicclassAShuttleLocationimplementsShuttleLocation { … }

  17. Explicit and Implicit Label Pattern importutil.annotations.StructurePattern; importutil.annotations.StructurePatternNames; @StructurePattern(StructurePatternNames.LABEL_PATTERN) publicclassAnotherShuttleimplementsSpecificImageLabel { staticfinal String IMAGE = "shuttle2.jpg“; staticfinalintWIDTH = 80; staticfinalintHEIGHT = 25; Point location; publicAShuttle (intinitX, intinitY) { location = newACartesianPoint(initX, initY); } publicAShuttle () { location = newACartesianPoint(50, 50); } public Point getLocation() {returnlocation;} publicvoidsetLocation(Point newVal) {location = newVal;} publicintgetWidth() { returnWIDTH;} publicintgetHeight() {returnHEIGHT;} public String getImageFileName() {returnIMAGE;} }

  18. Explicit and Attempted Implicit Label Pattern importutil.annotations.StructurePattern; importutil.annotations.StructurePatternNames; @StructurePattern(StructurePatternNames.LABEL_PATTERN) publicclassAnotherShuttleimplementsSpecificImageLabel { staticfinal String IMAGE = "shuttle2.jpg“; staticfinalintWIDTH = 80; staticfinalintHEIGHT = 25; Point location; publicAShuttle (intinitX, intinitY) { location = newACartesianPoint(initX, initY); } publicAShuttle () { location = newACartesianPoint(50, 50); } public Point getLocation() {returnlocation;} publicvoidsetLocation(Point newVal) {location = newVal;} publicintgetWidth() { returnWIDTH;} publicintgetHeight() {returnHEIGHT;} //public String getImageFileName() {return IMAGE;} }

  19. BMI Calculator Pattern? publicclassABMICalculator { publicdoublecalculateBMI(double height, double weight) { returnweight/(height*height); } }

  20. BMI Calculator Pattern? @StructurePattern(StructurePatternNames.NO_PATTERN) publicclassAnAnnotatedBMICalculator { publicdoublecalculateBMI(double height, double weight) { returnweight/(height*height); } }

  21. BMI Calculator Pattern? @StructurePattern(StructurePatternNames.BEAN_PATTERN) publicclassAnAnnotatedBMICalculator { publicdoublecalculateBMI(double height, double weight) { returnweight/(height*height); } }

  22. Bean Pattern? @StructurePattern(StructurePatternNames.BEAN_PATTERN) publicclassABMISpreadsheetNotFollowingBeanConventions { doubleheight = 1.77; doubleweight = 75; publicdoublegetWeight() { returnweight; } publicvoidset(doublenewWeight, doublenewHeight) { weight= newWeight; height= newHeight; } publicdoublegetHeight() { returnheight; } publicvoidsetHeight(intnewHeight) { height= newHeight; } publicdoubleBMI() { returnweight/(height*height); } }

  23. (Editable) Property Name Annotations @StructurePattern(StructurePatternNames.BEAN_PATTERN) @PropertyNames({ "Height", "Weight", "BMI"}) @EditablePropertyNames({"Height", "Weight"}) publicclassABMISpreadsheetNotFollowingBeanConventions { doubleheight = 1.77; doubleweight = 75; publicdoublegetWeight() { returnweight; } publicvoidset(doublenewWeight, doublenewHeight) { weight= newWeight; height= newHeight; } publicdoublegetHeight() { returnheight; } publicvoidsetHeight(intnewHeight) { height= newHeight; } publicdoubleBMI() { returnweight/(height*height); } }

  24. Order of Properties @StructurePattern(StructurePatternNames.BEAN_PATTERN) @PropertyNames({ "Weight", "Height", "BMI"}) @EditablePropertyNames({"Height", "Weight"}) publicclassABMISpreadsheetNotFollowingBeanConventions { doubleheight = 1.77; doubleweight = 75; publicdoublegetWeight() { returnweight; } publicvoidset(doublenewWeight, doublenewHeight) { weight= newWeight; height= newHeight; } publicdoublegetHeight() { returnheight; } publicvoidsetHeight(intnewHeight) { height= newHeight; } publicdoubleBMI() { returnweight/(height*height); } }

  25. Bean Pattern? @StructurePattern(StructurePatternNames.BEAN_PATTERN) publicclassABMISpreadsheetNotFollowingBeanConventions { doubleheight = 1.77; doubleweight = 75; publicdoublegetWeight() { returnweight; } publicvoidset(doublenewWeight, doublenewHeight) { weight= newWeight; height= newHeight; } publicdoublegetHeight() { returnheight; } publicvoidsetHeight(intnewHeight) { height= newHeight; } publicdoubleBMI() { returnweight/(height*height); } } Warning if (editable) properties not declared? Overhead, chances of mistake low, C# has built in support for properties Why warning if no structure annotation?

  26. Why Warnings • Accidental patterns • Efficiency

  27. Large Search Space publicclassStructurePatternNames { publicstaticfinal String NO_PATTERN = "No Pattern"; publicstaticfinal String BEAN_PATTERN = "Bean Pattern"; publicstaticfinal String POINT_PATTERN = "Point Pattern"; publicstaticfinal String LINE_PATTERN = "Line Pattern"; publicstaticfinal String OVAL_PATTERN = "Oval Pattern"; publicstaticfinal String RECTANGLE_PATTERN = "Rectangle Pattern"; publicstaticfinal String ARC_PATTERN = "Arc Pattern"; publicstaticfinal String LABEL_PATTERN = "Label Pattern"; publicstaticfinal String TEXT_PATTERN = "Text Pattern"; publicstaticfinal String STRING_PATTERN = "String Pattern"; publicstaticfinal String CURVE_PATTERN = "Curve Pattern"; publicstaticfinal String VECTOR_PATTERN = "Vector Pattern"; publicstaticfinal String LIST_PATTERN = "List Pattern"; publicstaticfinal String STACK_PATTERN = "Stack Pattern"; publicstaticfinal String HASHTABLE_PATTERN = "Hashtable Pattern"; publicstaticfinal String MAP_PATTERN = "Hashmap Pattern"; publicstaticfinal String ENUM_PATTERN = "Enum Pattern"; … } • Accidental patterns • Efficiency

More Related