tailieunhanh - Assembly Language: Step-by-Step - part 4

Tham khảo tài liệu 'assembly language: step-by-step - part 4', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | VendorA VendorB 128 Chapter 4 Print the list Dim Printitem As IReport For Each Printitem In Cars Next Figure Both VendorA and VendorB provide code. A method is needed to print each item so an interface is created called IReport. Notice that IReport is the data type that is used by Printitem when moving through the loop. This allows the Print method to be executed which will have a different output based on the object that executes the Print method. The .NET Framework and Visual Basic .NET Object Programming 129 The code listing is as follows VendorA Public Class GeneralCar Public VIN Make As String Public SeatingCapacity As Integer Public Sub New ByVal VIN As String ByVal Make As String _ ByVal SeatingCapacity As Integer VIN Make SeatingCapacity End Sub End Class VendorB Public Class SportsCar Public VIN Make As String Public TopSpeed As Integer Public Sub New ByVal VIN As String ByVal Make As String _ ByVal TopSpeed As Integer VIN Make TopSpeed End Sub End Class The assumption is that we did not have the above code. If we did we could simply add a Print method to the classes. Here is our code. Interface IReport Sub Print End Interface Public Class PrintableGenerlCar Inherits GeneralCar Implements IReport Public Sub New ByVal VIN As String ByVal Make As String _ ByVal SeatingCapacity As Integer VIN Make SeatingCapacity End Sub Public Sub Print Implements VIN 0 Make 1 Seating Capacity 2 VIN Make SeatingCapacity End Sub End Class Public Class PrintableSportsCar Inherits SportsCar Implements IReport Public Sub New ByVal VIN As String ByVal Make As String _ ByVal TopSpeed As Integer VIN Make TopSpeed End Sub 130 Chapter 4 Public Sub Print Implements VIN 0 Make 1 Top Speed 2 VIN Make TopSpeed End Sub End Class The following code is an example of using these new classes and the interface. An array of cars

TỪ KHÓA LIÊN QUAN