装饰模式+vb.net实现

前端之家收集整理的这篇文章主要介绍了装饰模式+vb.net实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

猜你在找的VB相关文章