ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

VB.NET ¤¶­±(Interface)

VB.NET ¤¶­±(Interface)

¤¶­±(Interface)

Constract(¦X¬ù)

©w¸qMethod³W¹º

*¥iÂX¥R  Aggregation(»E¦X)

¤¶­± 1

'¤¶­±¦X¬ù(¥\¯à-µ{§Ç(method or porperty)¦X¬ù  

2 Public Interface IWork  

3     '©wÀ³¤u§@¦X¬ù³W½d¹w³]¬°©â¶H  

4     Sub working(ByVal thing As String)  

5 End Interface

¤¶­± 2



view sourceprint?1 Public Interface ISales  

2     '·~°È±À¼s  

3     Sub Promotion()  

4   

5 End Interface

¹ê§@¤¶­±Ãþ§O1 : ¹ê§@ ¤¶­±1



view sourceprint?1 '¹ê§@¤¶­±  

2 Public Class Employee  

3     Implements IWork  

4     '¤u§@¯à¤O  

5     Public Sub working(ByVal thing As String) Implements IWork.working  

6         System.Console.WriteLine(String.Format("°µ...{0} ¦ó®É:{1:D}", thing, DateTime.Now))  

7     End Sub

8 End Class

¹ê§@¤¶­±Ãþ§O2 : ¹ê§@ ¤¶­±1©M¤¶­±2



view sourceprint?01 Public Class KHHEmployee  

02     '¹ê°µ¦P¼Ëªº¤¶­±  

03     Implements IWork, ISales  

04   

05     '¤u§@  

06     Public Sub working(ByVal thing As String) Implements IWork.working  

07         System.Console.WriteLine(String.Format("KHH­û¤u °µ...{0} ¦ó®É:{1:D}", thing, DateTime.Now))  

08     End Sub

09     '·~°È±À¼s  

10     Public Sub Promotion() Implements ISales.Promotion  

11         System.Console.WriteLine("KHH·~°È±À¼s!!")  

12     End Sub

13 End Class

Agent :¥N²z



view sourceprint?01 Public Class Company  

02     'Aggregation¨Ì¦sÃö«Y(Pull©Ô¦¡)  

03     '¤½¥q½Ð¹L¨Ó¤H¤O¥ò¤¶  

04     Private _service As WorkingService = New WorkingService()  

05     'ÄÝ©Ê ¨ú±oServicer  

06     'Public ReadOnly Property Service() As WorkingService  

07     '    Get  

08     '        Return _service  

09     '    End Get  

10   

11     'End Property  

12     'µ¡¤fMethod(Proxy) ¥N²z­È¦æworkingService.addEmployee()  

13     Public Sub addEmployee(ByVal emp As IWork)  

14         If (Not emp Is Nothing) Then

15             _service.addEmployee(emp)  

16         End If

17     End Sub

18     '­n¨D©Ò¦³­û¤u¤u§@  

19     Public Sub doWork()  

20         '±½´y¨C¤@­Ó¤£¦PÃþ«¬­û¤u(¨S¦³Ä~©ÓÃö«Y)  

21         For Each w As IWork In _service.Employees  

22             '§PÂ_¯S®íÃþ«¬ª«¥ó  

23             If TypeOf w Is KHHEmployee Then

24                 w.working("¸ê°T¤u§@...")  

25                 '¹ê°µ·~°È¤¶­±  

26                 DirectCast(w, ISales).Promotion()  

27             Else

28                 w.working("¤u§@...")  

29             End If

30         Next

31     End Sub

32 End Class

¥D­nÃþ§O



view sourceprint?01 Public Class Company  

02     'Aggregation¨Ì¦sÃö«Y(Pull©Ô¦¡)  

03     '¤½¥q½Ð¹L¨Ó¤H¤O¥ò¤¶  

04     Private _service As WorkingService = New WorkingService()  

05     'ÄÝ©Ê ¨ú±oServicer  

06     'Public ReadOnly Property Service() As WorkingService  

07     '    Get  

08     '        Return _service  

09     '    End Get  

10   

11     'End Property  

12     'µ¡¤fMethod(Proxy) ¥N²z­È¦æworkingService.addEmployee()  

13     Public Sub addEmployee(ByVal emp As IWork)  

14         If (Not emp Is Nothing) Then

15             _service.addEmployee(emp)  

16         End If

17     End Sub

18     '­n¨D©Ò¦³­û¤u¤u§@  

19     Public Sub doWork()  

20         '±½´y¨C¤@­Ó¤£¦PÃþ«¬­û¤u(¨S¦³Ä~©ÓÃö«Y)  

21         For Each w As IWork In _service.Employees  

22             '§PÂ_¯S®íÃþ«¬ª«¥ó  

23             If TypeOf w Is KHHEmployee Then

24                 w.working("¸ê°T¤u§@...")  

25                 '¹ê°µ·~°È¤¶­±  

26                 DirectCast(w, ISales).Promotion()  

27             Else

28                 w.working("¤u§@...")  

29             End If

30         Next

31     End Sub

32 End Class

¥Dµ{¦¡



view sourceprint?01 Module TestCompany  

02     '¥Dµ{¦¡  

03     Public Sub Main()  

04         '«Øºc¤½¥qª«¥ó->©Ô¥XWorkingService->List¶°¦Xª«¥ó  

05         Dim com As New Company()  

06         '¼x¨D­û¤u -°Ý¥X¤º³¡°Ñ¦ÒWorkingService  

07         'Dim service As WorkingService = com.Service  

08         '¥[­û¤u  

09         com.addEmployee(New Employee())  

10         com.addEmployee(New KHHEmployee())  

11         com.addEmployee(New Employee())  

12   

13         '¤½¥q©Ò¦³­û¤u¤u§@  

14         com.doWork()  

15     End Sub

16 End Module
­Ó¤Hñ¦W@

        ÀR«ä¦Û¦b : ¦Y­W¤F­W¡B­WºÉ¤Ü¨Ó¡A¨ÉºÖ¤FºÖ¡BºÖºÉ´d¨Ó¡C
ªð¦^¦Cªí ¤W¤@¥DÃD