CLASS ZCL_GOL_15 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    METHODS CELL_SURVIVES
      RETURNING
        VALUE(R_RESULT) TYPE ABAP_BOOL.
    METHODS: GET_LIVE_NEIGHBOURS RETURNING VALUE(R_RESULT) TYPE I,
      SET_LIVE_NEIGHBOURS IMPORTING I_LIVE_NEIGHBOURS TYPE I.
    METHODS:
      CONSTRUCTOR
        IMPORTING
          I_CURRENT_STATE TYPE ABAP_BOOL.
  PROTECTED SECTION.
  PRIVATE SECTION.
    DATA:
      LIVE_NEIGHBOURS TYPE I
      ,
      CURRENT_STATE   TYPE ABAP_BOOL.
ENDCLASS.



CLASS ZCL_GOL_15 IMPLEMENTATION.


  METHOD CELL_SURVIVES.

    R_RESULT = ABAP_FALSE.
    IF CURRENT_STATE = ABAP_TRUE.
      IF LIVE_NEIGHBOURS = 2 OR LIVE_NEIGHBOURS = 3.
        R_RESULT = ABAP_TRUE.
      ENDIF.
    ELSE.
      IF LIVE_NEIGHBOURS = 3.
        R_RESULT = ABAP_TRUE.
      ENDIF.
    ENDIF.
  ENDMETHOD.


  METHOD CONSTRUCTOR.
    CURRENT_STATE = I_CURRENT_STATE.
  ENDMETHOD.


  METHOD GET_LIVE_NEIGHBOURS.
    R_RESULT = ME->LIVE_NEIGHBOURS.
  ENDMETHOD.


  METHOD SET_LIVE_NEIGHBOURS.
    ME->LIVE_NEIGHBOURS = I_LIVE_NEIGHBOURS.
  ENDMETHOD.
ENDCLASS.
