欢迎光临
我们一直在努力

设计模式之工厂方法(FACTORY METHOD))(三)-.NET教程,数据库应用

建站超值云服务器,限时71元/月

(接上页)

straight seeding类

在这个小程序在实际应用当中,会发现大部分工作在straight seeding类中完成的。我们实例化straightseeding 类,复制、修改游泳运动员的集合和所属泳道位置。

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 swimmers 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 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

当调用getswimmers方法时,straightseeding 类将创建被选拔的游泳运动员数组。

circle seeding类

circleseeding 类是从straightseeding 类派生的。

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) 排序

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 设计模式之工厂方法(FACTORY METHOD))(三)-.NET教程,数据库应用
分享到: 更多 (0)