Page 281 - 6253
P. 281

Додаток Д


                                Приклад використання основних парадигм ООП


            /**
             * Created by Mykola Demchyna on 24.03.2018.
             */

            abstract public class Shape {

                protected static final double PI = 3.14;

                private String color;
                private Border borderStyle;

                public Shape(String color, Border borderStyle) {
                    this.color = color;
                    this.borderStyle = borderStyle;
                }

                public String getColor() {
                    return color;
                }

                public void setColor(String color) {
                    this.color = color;
                }

                public Border getBorderStyle() {
                    return borderStyle;
                }

                public void setBorderStyle(Border borderStyle) {
                    this.borderStyle = borderStyle;
                }

                public abstract double getArea();

                protected void shapeInfo() {
                    System.out.println("\tcolor: " + color + ", border style: " +
            borderStyle.toString().toLowerCase());
                }
            }

            /**
             * Created by Mykola Demchyna on 24.03.2018.
             */

            public enum Border {
                SOLID, DASHED, DOTTED
            }

            /**
             * Created by Mykola Demchyna on 24.03.2018.
             */

            public class Square extends Shape implements IPerimeter, IVertex {

                private double side;

                public Square(double side, String color, Border borderStyle) {
                    super(color, borderStyle);

                                                              280
   276   277   278   279   280   281   282   283   284   285