拖了好长时间的篇博文。
开始写主要目的是把新学习这门冷门语言的过程记录下来。因为新工作重心是OpenEdge ABL (原Progress) 语言的使用,对于原来只接触过Java并且不算精通的自己来说,还是有一定难度。
这门冷门的语言背景先不在这里介绍。也是因为在工作中发现这门语言的资料和问题解决方法在网上比较少。所以,多一个人分享经验多一件好事儿嘛。
学习阶段用Progress写的一个练手用计算器程序。用到了Open Edge ABL 的面向对象特性,和Java类似。
和Java的不同点:
1:没有类似main method 的入口方法。需要从.p文件调用.cls文件的方法来执行。
2:方法参数并不是只能Input。也有Output 参数。在这个例子中没有体现。
3:参数和变量声明类型以数据类型为主,并没有String类型,需要字符串需要character类型。
CalculateInterface.cls :
USING Progress.Lang.*.
INTERFACE CalculateInterface:
METHOD PUBLIC DECIMAL summation(INPUT number1 AS DECIMAL, INPUT number2 AS DECIMAL).
METHOD PUBLIC DECIMAL subtraction(INPUT number1 AS DECIMAL , INPUT number2 AS DECIMAL).
METHOD PUBLIC DECIMAL mutiplication(INPUT number1 AS DECIMAL , INPUT number2 AS DECIMAL).
METHOD PUBLIC DECIMAL division(INPUT dividend AS DECIMAL , INPUT divisor AS DECIMAL).
METHOD PUBLIC DECIMAL modular(INPUT moduled AS DECIMAL , INPUT modular AS DECIMAL).
END INTERFACE.
CalculateImpl.cls
USING Progress.Lang.*. BLOCK-LEVEL ON ERROR UNDO, THROW. CLASS CalculateImpl IMPLEMENTS CalculateInterface: METHOD PUBLIC DECIMAL summation(INPUT number1 AS DECIMAL, INPUT number2 AS DECIMAL): DEFINE VARIABLE valResult AS DECIMAL. ASSIGN valResult = number1 + number2. RETURN valResult. END METHOD. METHOD PUBLIC DECIMAL subtraction(INPUT number1 AS DECIMAL, INPUT number2 AS DECIMAL): DEFINE VARIABLE valResult AS DECIMAL. valResult = number1 - number2. RETURN valResult. END METHOD. METHOD PUBLIC DECIMAL mutiplication(INPUT number1 AS DECIMAL,INPUT number2 AS DECIMAL): DEFINE VARIABLE valResult AS DECIMAL. ASSIGN valResult = number1 * number2. RETURN valResult. END METHOD. METHOD PUBLIC DECIMAL division(INPUT dividend AS DECIMAL, INPUT divisior AS DECIMAL): DEFINE VARIABLE valResult AS DECIMAL. IF divisior = 0 THEN DO: DISPLAY "ERROR:DIVISOR equals zero". END. ELSE DO: ASSIGN valResult = dividend / divisior. RETURN valResult. END. END METHOD. METHOD PUBLIC DECIMAL modular(INPUT moduled AS DECIMAL , INPUT modular AS DECIMAL): DEFINE VARIABLE valResult AS DECIMAL. IF modular = 0 THEN DO: DISPLAY "ERROR: MODULAR equals zero". END. ELSE DO: ASSIGN valResult = moduled MODULO modular. RETURN valResult. END. END METHOD. END CLASS.
calUnitTest.p
BLOCK-LEVEL ON ERROR UNDO, THROW. DEFINE VARIABLE number1 AS DECIMAL INITIAL "5". DEFINE VARIABLE number2 AS DECIMAL INITIAL "10". DEFINE VARIABLE calResult1 AS DECIMAL. DEFINE VARIABLE calResult2 AS DECIMAL. DEFINE VARIABLE calResult3 AS DECIMAL. DEFINE VARIABLE calResult4 AS DECIMAL. DEFINE VARIABLE calResult5 AS DECIMAL. DEFINE VARIABLE testMethod AS CalculateImpl. ASSIGN testMethod = NEW CalculateImpl(). ASSIGN calResult1 = testMethod:summation(number1,number2). DISPLAY "Summation result :". DISPLAY calResult1. ASSIGN calResult2 = testMethod:subtraction(number1,number2). DISPLAY "subtraction result :". DISPLAY calResult2. ASSIGN calResult3 = testMethod:mutiplication(number1,number2). DISPLAY "mutiplication result :". DISPLAY calResult3. ASSIGN calResult4 = testMethod:division(number1,number2). DISPLAY "division result :". DISPLAY calResult4. ASSIGN calResult5 = testMethod:modular(number1,number2). DISPLAY "division result :". DISPLAY calResult5.