Business verification design in System Design 1

Source: Internet
Author: User

Business verification requirements can be roughly divided into three categories

1. A value must be verified.

2. A value must be verified only when another value appears.

3. A value needs to be verified only when one data in another data set meets a certain condition.

Business logic verification requires that verification methods be processed in a centralized manner, so as to avoid multiple business verification for the same value in the system as much as possible.

Verification: return the true or false method. This method must contain two parameters: 1. verify the data itself; 2. verify the data processing method.

Technologies that must be understood during verification:

Delegate: indicates a delegate. A delegate is a data structure that references static methods or class instances and class instance methods. The class that requires the parameters of the referenced method and the return value to be consistent with the method declared by Delegate. The method of this class can be called by the delegate type.

Here are two examples:

Example 1:

Public class samplesdelegate

'Declare the delegate for a method
Delegate function mymethoddelegate (Myint as integer) as [String]

'Declare the methods that can be pointed to by the delegate
Public class mysampleclass

'Define the method to be instantiated.
Public Function mystringmethod (Myint as integer) as [String]
If Myint> 0 then
Return "positive"
End if
If Myint <0 then
Return "negative"
End if
Return "zero"
End function 'mystringmethod

'Define static methods
Public shared function mysignmethod (Myint as integer) as [String]
If Myint> 0 then
Return "+"
End if
If Myint <0 then
Return "-"
End if
Return ""
End function 'mysignmethod
End Class 'mysampleclass

Public shared sub main ()

'Declare a delegate for each method: myd1, myd2.
Dim mysc as new mysampleclass ()
Dim myd1 as new mymethoddelegate (addressof mysc. mystringmethod) 'reference the instance method
Dim myd2 as new mymethoddelegate (addressof mysampleclass. mysignmethod) 'References static methods

'Call by Delegate.
Console. writeline ("{0} is {1}; Use the sign" "{2}" ".", 5, myd1 (5), myd2 (5 ))
Console. writeline ("{0} is {1}; Use the sign" "{2 }"". ",-3, myd1 (-3), myd2 (-3 ))
Console. writeline ("{0} is {1}; Use the sign" "{2}" ".", 0, myd1 (0), myd2 (0 ))

End sub 'main

End Class 'samplesdelegate

Example 2:

Public Class SortClass
'Declare the delegateDelegateFunction compare (byval X as integer, _ byval y as integer) as Boolean 'declares the instance method to which the delegate points
Function comparevalues (byval X as integer, _ byval y as integer) as Boolean if x> Y then comparevalues = true else comparevalues = false end if end function' declares the delegate Method
Sub selectionsort (byval isgreaterthanCompare, _ Byval intarray () as integer) dim maxval as integer dim maxindex as integer dim I, J as integer 'step through the elements in the array starting with the 'last element in the array. for I = ubound (intarray) to 1 step-1 maxval = intarray (I) maxindex = I for j = 1 to I 'use the delegate. ifIsgreaterthan. Invoke (intarray (J), maxval) Then maxval = intarray (j) maxindex = J end if next J' use delegate. IfIsgreaterthan. Invoke (I, maxindex) Then intarray (maxindex) = intarray (I) = maxval end if next I end subend classclass class1 sub sortarray ()
'Declare the instantiated object dim to which the delegate pointsSortAs new sortclass () dim arr1 () as integer = {1, 5, 3, 2, 7, 22, 5, 54, 12} Sort. selectionsort (addressofSort. Comparevalues, arr1) msgbox ("array sorted.") end subend class 'Test
Private sub button#click (byval sender as system. Object, _ byval e as system. eventargs) _ handles button1.click dim C as new class1 () C. sortarray () end sub
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.