加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

装饰模式+vb.net实现

发布时间:2020-12-16 23:03:54 所属栏目:大数据 来源:网络整理
导读:Module Module1 Sub Main() Dim hu As New huyang hu.name = "mm" '开始装饰 Console.WriteLine("。。。开始装饰。。。。") '定义装饰的对象,以及被装饰的人 Dim dc As New DecoratorCool() Dim dc2 As New DecoratorCool2() dc.getperson(hu) dc2.getperso

Module Module1
Sub Main()

Dim hu As New huyang
hu.name = "mm"
'开始装饰
Console.WriteLine("。。。开始装饰。。。。")
'定义装饰的对象,以及被装饰的人
Dim dc As New DecoratorCool()
Dim dc2 As New DecoratorCool2()
dc.getperson(hu)
dc2.getperson(dc)
dc2.show()
Console.ReadKey()
End Sub
End Module
'抽象人的基类
Public MustInherit Class Person
'具体的人
Protected Shared _name As String = "I"

Public WriteOnly Property name() As String
Set(ByVal value As String)
_name = value
End Set
End Property

'打扮
MustOverride Sub show()

End Class

Public Class huyang : Inherits Person

Public Overrides Sub show()
Console.WriteLine("{0}穿上外套。。。。",_name)
End Sub


End Class
'定义装饰类
Public Class Decorator : Inherits Person

Protected _person As Person

Public Sub getperson(ByVal person As Person)
_person = person
End Sub
Public Overrides Sub show()
_person.show()
End Sub

End Class'添加酷帅的墨镜效果 Public Class DecoratorCool : Inherits Decorator Public Overrides Sub show() MyBase.show() Console.WriteLine("{0}带上墨镜。。。出门去",_name) End SubEnd Class'添加酷帅的化妆效果 Public Class DecoratorCool2 : Inherits Decorator Public Overrides Sub show() MyBase.show() Console.WriteLine("{0}化妆。。。出门去",_name) End SubEnd Class

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读