Version 0.1 of Virtual Studio allows users to create shapes, place them on a canvas, and display them:
In this initial version of VS there are four types of shape, simple shapes-- polygons, texts, circles-- and group shapes. A group shape is several shapes grouped together as a single shape.
· All shapes have a draw method that uses a Java's Graphics parameter to do the actual art work.
· All shapes can be moved around the canvas. This is done by the translate method, which shifts the shape by adding a point to each point in the shape.
· A point has integer x and y coordinates. Points are examples of value objects. Points can be added to each other.
· A simple shape has a color.
· A polygon consists of three or more vertices. A vertex is a point.
· A label has an upper left corner and a string to be displayed.
· A Circle has an integer radius and a center point. Unfortunately, Circle does not extend SimpleShape and can't be modified.
· A group has many component shapes.
Here's the code that drew the canvas above:
Here's the code for displaying a canvas:
Here’s the code for mos of the
other classes:
· Heterogeneous Collection
o The shapes on a canvas can be a mixture of circles, polygons, labels, and groups.
o The members of a group can also be a mixture of circles, polygons, labels, and groups.
o These collections are implemented as sets because they don't have a relevant ordering and members should be unique.
· Abstract Classes vs. Interfaces
o An abstract method has no implementation. Or it might be better to say that it has multiple implementations found in other classes.
o Abstract classes and interfaces contain abstract method declarations.
o One difference is that an interface only contains abstract method declarations, while an abstract class may contain fields and concrete (i.e., implemented) methods.
o Another difference is that a class may implement many interfaces but extends at most one class.
o SimpleShape had to be an abstract class because it defines the concrete, inheritable property of color.
o Although SimpleShape contains no abstract methods and therefore could technically be implemented, we make it abstract because the concept it represents is abstract. "Shape" is simply a word used to collectively refer to concrete shapes such as polygons and circles.
· Value vs. Reference Objects
o Point is a good example of a value object.
· Lists vs. Sets
· Composite Pattern
· Adapter Pattern
Complete and test the implementation of Virtual Studio.