Re: Example Business Object (Customer)
Posted: Fri Nov 30, 2018 2:23 am
Here is an example of a method for the customer class that returns all the customer's invoices.
Instead of returning just an array of invoice numbers, it returns an array of invoice objects. This allows us to use any of the data and/or methods of the objects. Very useful. You could, for example, use the invoice number, date and total in a report.
Note that it is fully encapsulated--it opens it's own copy of the invoice file, uses it, then closes it.
Instead of returning just an array of invoice numbers, it returns an array of invoice objects. This allows us to use any of the data and/or methods of the objects. Very useful. You could, for example, use the invoice number, date and total in a report.
Note that it is fully encapsulated--it opens it's own copy of the invoice file, uses it, then closes it.
Code: Select all | Expand
Method GetInvoices() Class TCustomer
Local oInvoices := TInvoices():New()
Local aInvoices := {}
oInvoices:setOrder( "CUSTNO" )
oInvoices:setScope( ::CustNo, ::CustNo )
oInvoices:gotop()
do while .not. oInvoices:eof
aadd( aInvoices, TInvoice():New( oInvoices:InvNo ) )
oInvoices:skip()
enddo
oInvoices:end()
Return aInvoices