Hi all,
I have been asked to do some coding on a project that uses classes. It has been a while since I did OOP in college and when I did before it was with java. I am struggling to understand a few concepts and I have a few questions that maybe one of you could answer.
Just to explain what happened before:
At the front end I run appserver procedure and pass it a output temp-table which mirrors an actual database table .
At the back end the app server procedure populates the received temp table with data from the actual table and passes the temp table to the front end to display which displays the table in a browser program.
At the front end every time the user adds, deletes or modifyies a record. A procedure on the app server is run and the relevant detail are passed to the back end. E.g. run deleteEmployee on ... (ipiEmpID).
I am trying to model the above behaviour with using classes.
On the app server I intend to have a class to replace the back end procedure
Example (which runs with sports2000 database).
Say I have a Table Employee in a database defined as.
Say I run this at the front end using
I have a few questions.
1. Is there any point in having methods such as GetEmployeeName given I pass the temp table to the front end. I would think not but I am not sure.
2. I am not sure I have fully understood the concept of Final in OOP. I know a final Class cannot be inherited. I have declared the class as final because it updates the database and I don't want other classes inheriting an employee, overloading it and updating the data in the employee table. Is this correct or is this overkill?
3. Could someone please explain the difference between a property and a data member. I don't understand what the difference between a data member (such as my temp table) and a property is. It seems almost duplication of a data member. Why would I ever would ever want to use a property.
Can anyone point me if I am on the right track here please.
I have been asked to do some coding on a project that uses classes. It has been a while since I did OOP in college and when I did before it was with java. I am struggling to understand a few concepts and I have a few questions that maybe one of you could answer.
Just to explain what happened before:
At the front end I run appserver procedure and pass it a output temp-table which mirrors an actual database table .
At the back end the app server procedure populates the received temp table with data from the actual table and passes the temp table to the front end to display which displays the table in a browser program.
At the front end every time the user adds, deletes or modifyies a record. A procedure on the app server is run and the relevant detail are passed to the back end. E.g. run deleteEmployee on ... (ipiEmpID).
I am trying to model the above behaviour with using classes.
On the app server I intend to have a class to replace the back end procedure
Example (which runs with sports2000 database).
Say I have a Table Employee in a database defined as.
Code:
EmpNum inte
LastName char
FirstName char
Birthdate date
StartDate date
Code:
USING Progress.Lang.*.
CLASS Employee FINAL:
DEFINE PRIVATE TEMP-TABLE tt-Employee NO-UNDO
FIELD EmpNum AS INTEGER
FIELD FirstName AS CHARACTER
FIELD LastName AS CHARACTER
FIELD BirthDate AS DATE
FIELD StartDate AS DATE
INDEX PrimIdx IS PRIMARY EmpNum .
/**
* Called automatically to initialise the class before the instance is created or any static
* members are referenced. Cannot be called directly. Typical use is to initialise logging.
*/
CONSTRUCTOR STATIC Employee ():
END CONSTRUCTOR.
METHOD PUBLIC HANDLE GetEmployeeList():
EMPTY TEMP-TABLE tt-Employee.
FOR EACH Employee NO-LOCK:
CREATE tt-Employee.
BUFFER-COPY Employee TO tt-Employee.
END.
RETURN TEMP-TABLE tt-Employee:HANDLE.
END METHOD.
METHOD PUBLIC LOGICAL SetEmployee (INPUT ipiEmpNum AS INTEGER,
INPUT ipchFName AS CHARACTER,
INPUT ipchLName AS CHARACTER,
INPUT ipdaDOB AS DATE,
INPUT ipdaStart AS DATE):
FIND FIRST Employee WHERE Employee.EmpNum = ipiEmpNum EXCLUSIVE-LOCK NO-ERROR NO-WAIT.
IF NOT AVAILABLE (employee) THEN DO:
CREATE Employee.
ASSIGN Employee.EmpNum = ipiEmpNum.
END.
ASSIGN Employee.FirstName = ipchFName
Employee.LastName = ipchLName
Employee.BirthDate = ipdaDOB
Employee.StartDate = ipdaStart.
END METHOD.
METHOD PUBLIC CHARACTER GetEmployeeName (INPUT ipiEmpNum AS INTEGER):
DEFINE VARIABLE vchName AS CHARACTER NO-UNDO.
ASSIGN vchName = "".
FIND FIRST Employee WHERE employee.EmpNum = ipiEmpNum NO-LOCK NO-ERROR.
IF AVAILABLE Employee THEN
ASSIGN vchName = Employee.FirstName + " " + Employee.LastName.
RETURN vchName.
END METHOD.
DESTRUCTOR Employee():
EMPTY TEMP-TABLE tt-Employee.
END.
END CLASS.
Say I run this at the front end using
Code:
DEFINE TEMP-TABLE tt-Employee NO-UNDO
FIELD EmpNum AS INTEGER
FIELD FirstName AS CHARACTER
FIELD LastName AS CHARACTER
FIELD BirthDate AS DATE
FIELD StartDate AS DATE
INDEX PrimIdx IS PRIMARY EmpNum .
DEFINE VARIABLE clsEmployee AS Employee NO-UNDO.
DEFINE VARIABLE vchEmployeeName AS CHARACTER NO-UNDO.
DEFINE VARIABLE vhdlTTTable AS HANDLE NO-UNDO.
DEFINE VARIABLE vhdlTTEmployee AS HANDLE NO-UNDO.
clsEmployee = NEW Employee().
ASSIGN vhdlTTTable = clsEmployee:GetEmployeeList()
vhdlTTEmployee = TEMP-TABLE tt-Employee:HANDLE.
vhdlTTEmployee:COPY-TEMP-TABLE(vhdlTTTable).
/* In a real siutation this would be populating a browse. */
FOR EACH tt-employee NO-LOCK:
DISP tt-employee.
END.
MESSAGE vhdlTTTable VIEW-AS ALERT-BOX.
I have a few questions.
1. Is there any point in having methods such as GetEmployeeName given I pass the temp table to the front end. I would think not but I am not sure.
2. I am not sure I have fully understood the concept of Final in OOP. I know a final Class cannot be inherited. I have declared the class as final because it updates the database and I don't want other classes inheriting an employee, overloading it and updating the data in the employee table. Is this correct or is this overkill?
3. Could someone please explain the difference between a property and a data member. I don't understand what the difference between a data member (such as my temp table) and a property is. It seems almost duplication of a data member. Why would I ever would ever want to use a property.
Can anyone point me if I am on the right track here please.