150 likes | 287 Views
Parameters and Their Options. caller ( ); begin // str and acc are arguments passed to the called method obj.called( str, acc ); end ;. called (pString : String ; pAccount : Account ); // pString and pAccount are parameters of the called method.
E N D
Parameters and Their Options • caller ( ); • begin • // str and acc are arguments passed to the called method • obj.called( str, acc ); • end; • called (pString : String; pAccount : Account); • // pString and pAccount are parameters of the called method • Parameter option determines how a parameter may be changed • If a change is allowed, the change is reflected in the argument • called (pString : String constant | input | output | io ; • pAccount : Account constant | input | output | io ); 9.1
constant • caller ( ); • begin • obj.called( str, acc ); • end; • called (pString : String constant; pAccount : Account constant); • begin • pString := 'Hello World'; // NOT allowed • pString.replaceChar('a', 'b'); // NOT allowed • pAccount := allAccounts.getAtKey('AN6374'); // NOT allowed • pAccount.balance := 0; // NOT allowed • pAccount.setBalance(0); // NOT allowed • end; • constant is the default option and need not be specified 9.2
input • caller ( ); • begin • obj.called( str, acc ); • end; • called (pString : String input; pAccount : Account input); • begin • pString := 'Hello World'; // NOT allowed • pString.replaceChar('a', 'b'); // allowed • pAccount := allAccounts.getAtKey('AN6374'); // NOT allowed • pAccount.balance := 0; // allowed • pAccount.setBalance(0); // allowed • end; 9.3
output • caller ( ); • begin • obj.called( str, acc ); • end; • called (pString : String output; pAccount : Account output); • begin • pString := 'Hello World'; // allowed • pString.replaceChar('a', 'b'); // allowed • pAccount := allAccounts.getAtKey('AN6374'); // allowed • pAccount.balance := 0; // allowed • pAccount.setBalance(0); // allowed • end; • output parameters are set to null at the start of the method 9.4
io • caller ( ); • begin • obj.called( str, acc ); • end; • called (pString : String io; pAccount : Account io); • begin • pString := 'Hello World'; // allowed • pString.replaceChar('a', 'b'); // allowed • pAccount := allAccounts.getAtKey('AN6374'); // allowed • pAccount.balance := 0; // allowed • pAccount.setBalance(0); // allowed • end; 9.5
RootSchema Examples • String primitive type • substring := longstring.scanUntil(delims, index); • // delims is constant • // index is io • Collection class • accountsByNumber.copy(accountsByName); • // accountsByName is input • Object class • getLockStatus(object, lockType, lockDuration, lockedBy); • // object is constant • // lockType, lockDuration, • lockedBy are output 9.6
Method Options • abstract • updating • protected • mapping • clientExecution • serverExecution • called ( pString : String; pAccount : Account ) updating, protected, serverExecution; 9.7
initTransaction (pMyAccount : Account; pMyBranch : Branch ) : String; vars str : String; begin if pMyAccount = nullthen str := 'A valid Account is required'; elseif pMyBranch = nullthen str := 'A Branch is required'; endif; return str; end; Return Value 9.8
Constructors and Destructors • Constructor • method called ‘create’ • executed after create instruction • Destructor • method called ‘delete’ • executed before delete instruction • create ( ) updating; • begin • self.password := 'password'; • end; 9.9
Mapping Methods • Same name as property • Reimplements default ‘get’ and ‘set’ behaviour • Defined signature • set parameter • true when property is updated • false when property is read name ( set : Boolean; _value : String io ) mapping; begin end; 9.10
Primitive Methods 9.11
External Methods • Same as JADE Method • name • parameters • options • Library • Entry Point • isValid( ): Booleanis"dateIsValid"in"jomsupp” ; 9.12
External Functions • Library • Entry Point in signature • Invoked using the call instruction // Open your internet browser call _shellExecute (null, 'open', 'http://www.discoverjade.com', null, null, null); // Open your email program call _shellExecute (null, 'open', 'mailto:gdavies@jade.co.nz?subject=Hello World&body=The traditional greeting.', null, null, null); 9.13
SequenceNumber number next() Bank myBankAcctSeqNum myCustomerSeqNum create() delete() nextBankAcctNum() nextCustomerNum() Challenge #18 In the BankingModelSchema • Add a SequenceNumber class • Add a SequenceNumber::number property • Code a SequenceNumber::next method thatincrements number and then returns that value In the Bank class • Add references to SequenceNumber calledmyCustomerSeqNum and myBankAcctSeqNum • Code a Bank constructor to create the references • Code a Bank destructor to delete the references • Code a Bank::nextBankAcctNumber method • Code a Bank::nextCustomerNumber method In the JadeScript class • Execute the createBank method 9.14
sequence number newcustomer bankroot object Challenge #19 What’s thenext number? In the BankingModelSchema add contructors to Customer and BankAccount that assign the next available number to the object 9.15