Author Topic: Modules  (Read 259 times)

0 Members and 1 Guest are viewing this topic.

John Spikowski

  • Posts: 36
Modules
« on: December 14, 2018, 05:25:43 PM »
I thought I would start off explaining how a MODULE works and how it is used like 100 uses simulated objects for code reuse.

Session Module
Code: Script BASIC
  1. MODULE Session
  2.  
  3.   PROP{"CompanyCode"} = "ABC"
  4.   PROP{"CompanyName"} = DefaultName()
  5.   PROP{"Version"} = 1.0
  6.  
  7.   FUNCTION DefaultName
  8.     DefaultName = "Acme Distribution Company"
  9.   END FUNCTION
  10.  
  11.   FUNCTION TimeJulian(y, m, d, m, s)
  12.     TimeJulian = TimeValue(y, m, d, m, s)
  13.   END FUNCTION
  14.  
  15. END MODULE
  16.  

Test Module
Code: Script BASIC
  1. 'Test Session Module
  2.  
  3. IMPORT "module.sb"
  4.  
  5. PRINT "Comapany Code: ",Session::PROP{"CompanyCode"}, "\n"
  6. PRINT "Comapany Name: ",Session::PROP{"CompanyName"}, "\n"
  7. PRINT FORMAT("Version Number: %.1f\n", Session::PROP{"Version"})
  8. PRINTNL
  9. PRINT "Julian Date/Time: ",Session::TimeJulian(2018,12,14), "\n"
  10.  

Output

jrs@jrs-laptop:~/SB2020$ scriba testmodule.sb
Comapany Code: ABC
Comapany Name: Acme Distribution Company
Version Number: 1.0

Julian Date/Time: 1544788800
jrs@jrs-laptop:~/SB2020$


John Spikowski

  • Posts: 36
Re: Modules - Inheritance
« Reply #1 on: December 15, 2018, 01:14:39 PM »
Here is an example of how MODULE Inheritance could be done to promote code reuse.

Session Module (our first MODULE example)
Code: Script BASIC
  1. MODULE Session
  2.  
  3.   PROP{"CompanyCode"} = "ABC"
  4.   PROP{"CompanyName"} = DefaultName()
  5.   PROP{"Version"} = 1.0
  6.  
  7.   FUNCTION DefaultName
  8.     DefaultName = "Acme Distribution Company"
  9.   END FUNCTION
  10.  
  11.   FUNCTION TimeJulian(y, m, d, m, s)
  12.     TimeJulian = TimeValue(y, m, d, m, s)
  13.   END FUNCTION
  14.  
  15. END MODULE
  16.  

New Object that inherits Session
Code: Script BASIC
  1. MODULE Inherited
  2.  
  3. ' Session MODULE
  4. IMPORT "module.sb"
  5.  
  6. PROP{"DefaultCompanyCode"} = Session::PROP{"CompanyCode"}
  7.  
  8. END MODULE
  9.  

Test new object MODULE.
Code: Script BASIC
  1. IMPORT "newobj.sb"
  2.  
  3. PRINT Inherited::PROP{"DefaultCompanyCode"},"\n"
  4.  

Output:


jrs@jrs-laptop:~/SB2020$ time scriba testobj.sb
ABC

real   0m0.006s
user   0m0.005s
sys   0m0.001s
jrs@jrs-laptop:~/SB2020$



« Last Edit: December 15, 2018, 02:46:19 PM by John Spikowski »