Java OOP GUIDE / WORK EXTREMABLE INTERFACE Topics
TASK –
PART 1 – UNDERSTANDING OUR SCENARIO (EXPLANATION) Let’s
imagine we will be creating a large application that will have different
types of shapes such as triangles, squares, pentagons and other
polygons. Let’s also imagine that we
need to be able to find the leftmost, rightmost, top and bottom extremes of
those shapes. For
example, for the shape below, the leftmost point is at x=143 and the
rightmost point is at 310. The top
point is at y=220 and the bottom at y=356. For
different types of shapes, the way that we find those extremes will be
different. For a circle, we might have
to add or subtract the radius from the center’s coordinates. For a polygon like in the example, we might
have to loop through all points and determine the max or min coordinate. TASK –
PART 2 – DESIGN DECISION (EXPLANATION) We
have a design decision to make. We can
simply create each class independently of each other and make sure each one
has the required functionality. So…
Let’s create the interface that assures that we can get the leftmost,
rightmost, topmost and bottommost points of a shape. TASK –
PART 3 – INTERFACE NAME (EXPLANATION) We
need to determine the interface’s name.
Since interfaces specify a functionality that a class has, many cool
people (like your teacher) like to use something that ends with –able but
this not required. Our
interface will provide the values of extremes of our shape. So it should be used with objects for which
it makes sense to find these extremes; objects that are extremable. Yes, I just invented a word. So
our interface’s name will be Extremable. TASK –
PART 4 – DETERMINING INTERFACE FUNCTIONALITY (EXPLANATION) We
now need to determine what methods are needed to provide the desired
functionality. In our case, we need a
method for each of the extreme values.
So our interface needs: ·
A
method that gives the leftmost point, ·
A
method that gives the rightmost point, ·
A
method that gives the topmost point, and ·
A
method that gives the bottommost point. TASK –
PART 5 – CREATE THE INTERFACE Create
the Extremable interface. |
|