标题:简单工厂模式
只看楼主
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
结帖率:78.95%
 问题点数:0 回复次数:0 
简单工厂模式
程序代码:
'简单工厂模式
Module Module1

    Sub Main()
        Dim MyCar As ICar = CarFactory.GetCarInterface("Benz")
        MyCar.CarRun()
        MyCar.CarStop()
        MyCar = CarFactory.GetCarInterface("Ford")
        MyCar.CarRun()
        MyCar.CarStop()
        System.Console.ReadLine()
    End Sub

End Module

Public Interface ICar
    Sub CarRun()
    Sub CarStop()
End Interface

Public Class Benz : Implements ICar  '奔驰汽车


    Public Sub CarRun() Implements ICar.CarRun
        System.Console.WriteLine("奔驰汽车启动了.......")
    End Sub

    Public Sub CarStop() Implements ICar.CarStop
        System.Console.WriteLine("奔驰汽车停车了.......")
    End Sub
End Class

Public Class Ford : Implements ICar  '福特汽车

    Public Sub CarRun() Implements ICar.CarRun
        System.Console.WriteLine("福特汽车启动了.......")
    End Sub

    Public Sub CarStop() Implements ICar.CarStop
        System.Console.WriteLine("福特汽车停车了.......")
    End Sub

End Class

Public Class CarFactory '汽车工厂
    Public Shared Function GetCarInterface(ByVal CarType As String) As ICar
        Select Case CarType
            Case "Benz"
                Return New Benz
            Case "Ford"
                Return New Ford
        End Select
        Return System.DBNull.Value
    End Function
End Class
搜索更多相关主题的帖子: 工厂 模式 
2008-02-17 13:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-200141-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.232090 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved