Design pattern of the factory method (FACTORY methods)) (iii)

Source: Internet
Author: User
Tags integer sort tostring
Design (connected to the page)

Straight Seeding Class



In the practical application of this applet, it is found that most of the work is done in the straight seeding class. We instantiate the Straightseeding class, copying and modifying the swimmers ' collection and the location of the swim lanes.



Public Class straightseeding

Inherits Seeding

Public Overrides Sub Seed ()

Dim Lastheat as Integer

Dim Lastlanes as Integer

Dim I, J, Count, heats as Integer

Dim SWMR as swimmer

Try

SW = sort (SW)

Laneorder = Calclaneorder (numlanes)

Count = SW. Count

Lastheat = Count Mod numlanes

If (Lastheat < 3) and Lastheat > 0 Then

Lastheat = 3 ' Last heat must have 3 or more

End If

Count = SW. Count

Lastlanes = Count-lastheat

Numheats = lastlanes \ Numlanes

If (lastheat > 0) Then

Numheats = numheats + 1

End If

Heats = Numheats

' Place heat and lane in each swimmer ' s object

j = 0

For i = 0 to Lastlanes-1

SWMR = SW.SWM (i)

Swmr.setlane (CType (Laneorder (j), Integer))

j = j + 1

Swmr.setheat (heats)

If (J >= Numlanes) Then

Heats = Heats-1

j = 0

End If

Next I

' Add in the last partial heat

If (lastheat > 0) Then

If J > 0 Then

Heats = Heats-1

End If

j = 0

For i = Lastlanes to Count-1

SWMR = CType (SW (i), swimmer)

Swmr.setlane (CType (Laneorder (j), Integer))

j = j + 1

Swmr.setheat (heats)

Next I

End If



Catch e as Exception

Console.WriteLine (i.tostring + j.tostring + e.tostring)

Console.WriteLine (E.stacktrace)

End Try

End Sub

'-----

Public Sub New (ByVal Swmrs as swimmers, ByVal lanes as Integer)

MyBase.New (Swmrs, lanes)

End Sub

End Class

When the Getswimmers method is invoked, the Straightseeding class creates an array of selected swimmers.

Circle Seeding Class



The Circleseeding class is derived from the Straightseeding class.



Public Class circleseeding

Inherits straightseeding



Private Circlesd as Integer

'-----

Public Sub New (ByVal Swmrs as swimmers, ByVal lanes as Integer)

MyBase.New (Swmrs, lanes)



End Sub

'-----

Public Overrides Sub Seed ()



Dim I, J, K, Numheats as Integer

Laneorder = Calclaneorder (numlanes)

SW = sort (sw) ' Order



Mybase.seed ()

Numheats = Mybase.getheats

If (numheats >= 2) Then

If (numheats >= 3) Then

CIRCLESD = 3

Else

CIRCLESD = 2

End If

i = 0



For j = 0 to NumLanes-1

For k = 1 to Circlesd

SW.SWM (i). Setlane (CType (Laneorder (j), Integer)

SW.SWM (i). Setheat (numheats-k + 1)

i = i + 1

Next K

Next J

End If

End Sub

'-----

End Class





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.