中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 教育认证 > 软件水平考试 > 经验交流
设计模式之工厂方法FACTORYMETHOD(三)
作者:佚名 时间:2005-05-13 11:21 出处:互连网 责编:chinaitpower
              摘要:设计模式之工厂方法FACTORYMETHOD(三)

  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 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 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
  
  运行
  在这个例子当中,我们使用完成500m自由泳和100m自由泳的运动员列表来创建TimedFinalEvent 类和PrelimEvent类。
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有