Object-Oriented Batch Language (Object Oriented Batch Language)
The text, code, and ideas in this article come from the following reference:
BATCH PROGRAMMING ELEMENTS (Dirk van Deun)
Chap 9: “Object Oriented Batch Language”
http://student.vub.ac.be/~dvandeun/batcoll.all
Special thanks to Dirk van Deun for his contribution!
I came across this article two years ago, but never paid it enough attention. A few days ago I suddenly dug it out again, and only then realized the value hidden in it. In it, the implementation of “object orientation” makes an important breakthrough in batch programming ideas, and its idea of using file structures to simulate data structures was also very enlightening to me.
The program uses file directories to simulate class libraries and object libraries, files to simulate the properties and methods owned by classes, and batch files to simulate object references, thus implementing the four major structures of OOP: classes, objects, properties, and methods, and thereby also implementing OOP features such as inheritance and overriding.
After thoroughly studying the program, I decided to make some modifications:
First, I rewrote all the code using internal commands, solving cross-platform portability as much as possible. At present, partial testing has been carried out and passed under MSDOS6.22/7.10 and the WindowsXP command line. My design goal is to make it run normally across the full MSDOS/ Win9x / WinNT's platform series.
Second, I changed the way objects are defined and called; that is, objects are defined directly by class name, and properties and methods are referenced by object name, making it more in line with OOP coding habits.
Third, I improved the scheme for using OOBL in batch files; although the original program was called OOBL, in fact it could only work at the command line and could not have all its code written into a batch file.
Fourth, I added public/private access attributes for properties and methods, making data encapsulation possible.
Finally, I made major changes to the strategy of loading variables before calling object methods and saving variables afterward. This change was unavoidable, because otherwise Dirk's original push/pop scheme would introduce the external program edlin.exe; but this new strategy also brings many problems: object data and class data are obviously duplicated, making data redundancy and space usage increasingly prominent.
So far, this is still a half-finished product, and it still has rather major defects. For example, in order to keep the structure clear, no error-handling mechanism was added; as for constructors for objects in the design and polymorphic method invocation, there is still no mature solution.
But my current state is very bad. I spent a full two weeks on it, yet progress was very slow. So I can only release this immature code. If anyone in the field is interested, you can study it and see. I hope someone can continue the unfinished work.
Below is a command-line example of OOBL:
E:\Batch\Test\OOBL>project work
"work":class man
"work":proprt Name
"work":proprt FullName private
"work":method setName
set name=%1
set fullname=%2 %3
^Z
"work":method putName
echo Name:%name%; FullName:%fullname%
^Z
"work":class employee man
"work":proprt salary private
"work":method setSal
set salary=%1
^Z
"work":method putSal
echo Name:%name%; FullName:%fullname%; Salary:%salary%;
^Z
"work":man John
"work":John name=John
"work":man fred
"work":fred name=Fred
"work":fred setName Fred Fred Ford
"work":john putName
Name:John; FullName:
"work":fred putName
Name:Fred; FullName:Fred Ford
"work":employee bill
"work":bill name=Bill
"work":bill setSal $100000
"work":bill putSal
Name:Bill; FullName:; Salary:$100000;
"work":project :end
Project is end!
E:\Batch\Test\OOB>
A batch file example of OOBL is in the attachment
[ Last edited by willsort on 2005-8-4 at 19:47 ]
Attachments
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!

DigestI