| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1164 人关注过本帖
标题:抽象工厂模式
只看楼主 加入收藏
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
结帖率:78.95%
收藏
 问题点数:0 回复次数:0 
抽象工厂模式
程序代码:
'抽象工厂模式
Module Module1

    Sub Main()
        Dim man As New Man
        Dim yangsheng As New YangSheng
        man = yangsheng.GetPerson("Man")
        man.Eat()
        man.Talk()

        Dim bull As New Bull
        bull = yangsheng.GetAnimal("Bull")
        bull.Eat()
        bull.Sleep()

        Dim woman As New Woman
        Dim yinsheng As New YinSheng
        woman = yinsheng.GetPerson("Woman")
        woman.Eat()
        woman.Talk()

        Dim cow As New Cow
        cow = yinsheng.GetAnimal("Cow")
        cow.Eat()
        cow.Sleep()

        System.Console.ReadLine()


    End Sub

End Module

Public Interface IPerson   '人类工厂
    Sub Eat()
    Sub Talk()
End Interface

Public Interface IAnimal '动物工厂
    Sub Eat()
    Sub Sleep()
End Interface

Public Class Man : Implements IPerson  '男人

    Public Sub Eat() Implements IPerson.Eat
        System.Console.WriteLine("男人在吃东西...")
    End Sub

    Public Sub Talk() Implements IPerson.Talk
        System.Console.WriteLine("男人在说话...")
    End Sub

End Class

Public Class Woman : Implements IPerson '女人

    Public Sub Eat() Implements IPerson.Eat
        System.Console.WriteLine("女人在吃东西...")
    End Sub

    Public Sub Talk() Implements IPerson.Talk
        System.Console.WriteLine("女人在说话...")
    End Sub

End Class

Public Class Bull : Implements IAnimal '公牛

    Public Sub Eat() Implements IAnimal.Eat
        System.Console.WriteLine("公牛在吃东西...")
    End Sub

    Public Sub Sleep() Implements IAnimal.Sleep
        System.Console.WriteLine("公牛睡觉了...")
    End Sub

End Class

Public Class Cow : Implements IAnimal '母牛

    Public Sub Eat() Implements IAnimal.Eat
        System.Console.WriteLine("母牛在吃东西...")
    End Sub

    Public Sub Sleep() Implements IAnimal.Sleep
        System.Console.WriteLine("母牛睡觉了...")
    End Sub

End Class

Public Interface INWFactory  '女娲工厂

    Function GetPerson(ByVal PersonType As String) As IPerson
    Function GetAnimal(ByVal AnimalType As String) As IAnimal

End Interface

Public Class YangSheng : Implements INWFactory 'YangSheng-->阳绳 造雄性动物

    Public Function GetAnimal(ByVal AnimalType As String) As IAnimal Implements INWFactory.GetAnimal

        If AnimalType = "Bull" Then Return New Bull
        Return System.DBNull.Value

    End Function

    Public Function GetPerson(ByVal PersonType As String) As IPerson Implements INWFactory.GetPerson

        If PersonType = "Man" Then Return New Man
        Return System.DBNull.Value

    End Function

End Class

Public Class YinSheng : Implements INWFactory 'YinShen-->阴绳 造雌性动物

    Public Function GetAnimal(ByVal AnimalType As String) As IAnimal Implements INWFactory.GetAnimal

        If AnimalType = "Cow" Then Return New Cow
        Return System.DBNull.Value

    End Function

    Public Function GetPerson(ByVal PersonType As String) As IPerson Implements INWFactory.GetPerson

        If PersonType = "Woman" Then Return New Woman
        Return System.DBNull.Value

    End Function

End Class

搜索更多相关主题的帖子: 工厂 模式 
2008-02-17 15:56
快速回复:抽象工厂模式
数据加载中...
 
   



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

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