有人能用这个VB.Net代码发现问题吗?

有人能用这个VB.Net代码发现问题吗?,第1张

概述我正在VB.Net中编写一些代码,我希望通过各种设计模式向同事们展示(不要再熟悉一下) – 而且我遇到了FactoryMethod模式的问题. 这是我的代码: Namespace Patterns.Creational.FactoryMethod ''' <summary> ''' This is the Factory bit - the other classes are m 我正在VB.Net中编写一些代码,我希望通过各种设计模式向同事们展示(不要再熟悉一下) – 而且我遇到了FactoryMethod模式的问题.

这是我的代码:

namespace Patterns.Creational.FactoryMethod    ''' <summary>    ''' This is the Factory bit - the other classes are merely by way of an example...    ''' </summary>    Public Class CarFactory        ''' <summary>        ''' CreateCar Could have been declared as Shared (in other words,a Class method) - it doesn't really matter.        ''' Don't worry too much about the contents of the CreateCar method - the point is that it decIDes which type        ''' of car should be created,and then returns a new instance of that specific subclass of Car.        ''' </summary>        Public Function CreateCar() As Car            Dim blnMondeoCondition As Boolean = False            Dim blnFocusCondition As Boolean = False            Dim blnFIEstaCondition As Boolean = False            If blnMondeoCondition Then                Return New Mondeo()            ElseIf blnFocusCondition Then                Return New Focus()            ElseIf blnFIEstaCondition Then                Return New FIEsta()            Else                Throw New ApplicationException("Unable to create a car...")            End If        End Function    End Class    Public Mustinherit Class Car        Public MustOverrIDe Readonly Property Price() As Decimal    End Class    Public Class Mondeo inherits Car        Public Readonly OverrIDes Property Price() As Decimal            Get                Return 17000            End Get        End Property    End Class    Public Class Focus inherits Car        Public Readonly OverrIDes Property Price() As Decimal            Get                Return 14000            End Get        End Property    End Class    Public Class FIEsta inherits Car        Public Readonly OverrIDes Property Price() As Decimal            Get                Return 12000            End Get        End Property    End ClassEnd namespace

当我尝试编译它时,我在CarFactory.CreateCar中收到错误(BC30311),告诉我它无法将FIEsta,Mondeo和Focus转换为Car.我不知道问题是什么 – 它们都是Car的子类.

毫无疑问,我忽视了一些简单的事情.谁能发现它?

干杯,

马丁.

解决方法 您的inherits关键字必须在新行上. Microsoft在其帮助和支持中记录了这一点. http://support.microsoft.com/kb/307222

Change the SavingsAccount class deFinition as follows,so that SavingsAccount inherits from Account (note that the inherits keyword must appear on a new line):

总结

以上是内存溢出为你收集整理的有人能用这个VB.Net代码发现问题吗?全部内容,希望文章能够帮你解决有人能用这个VB.Net代码发现问题吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1236069.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存