468,541 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,541 developers. It's quick & easy.

Can I allow varying types on a MustOverride

I am looking to have a base class which provides that all inherited
classes MUST have some property, but that they can each define it as
whatever type they want. So maybe three class inherit from the base
class, each MUST have a [Type] property, but one defines it as
OracleType, one as SqlType and one as DB2Type, for example.

I know i can just declare it as Object, and then have the classes each
do typechecks on value assignment, but this is late-bound. I would like
some way to implement this so that the type-specificity of each class is
early-bound, allowing for compile time type checking.

Is this possible?

TIA-
- Aaron.

================================================== ============

This is what i want (generic code)...

Class BaseClass
Public MustOverride Property Type

... other class code ...
End Class

Class OraClass
Inherits BaseClass

Public Overrides Property Type As OracleType

... other class code ...
End Class

Class SqlClass
Inherits BaseClass

Public Overrides Property Type As SqlType

... other class code ...
End Class

Jul 21 '05 #1
1 1334
The only way I know of to do this is via polymorphism, if all the
types support a common interface. For example:

Class BaseClass
Public MustOverride Property Type As INativeDBType

... other class code ...
End Class

If OracleType and SqlType both implement interface INativeDBType, your
derived classes should work as declared below. Replace "INativeDBType"
with whatever the common interface is, if there is one. If not, I
don't think this can be done early-bound.


Eidolon <aa****@KILLSPAM.yahoo.com> wrote in message news:<em**************@TK2MSFTNGP09.phx.gbl>...
I am looking to have a base class which provides that all inherited
classes MUST have some property, but that they can each define it as
whatever type they want. So maybe three class inherit from the base
class, each MUST have a [Type] property, but one defines it as
OracleType, one as SqlType and one as DB2Type, for example.

I know i can just declare it as Object, and then have the classes each
do typechecks on value assignment, but this is late-bound. I would like
some way to implement this so that the type-specificity of each class is
early-bound, allowing for compile time type checking.

Is this possible?

TIA-
- Aaron.

================================================== ============

This is what i want (generic code)...

Class BaseClass
Public MustOverride Property Type

... other class code ...
End Class

Class OraClass
Inherits BaseClass

Public Overrides Property Type As OracleType

... other class code ...
End Class

Class SqlClass
Inherits BaseClass

Public Overrides Property Type As SqlType

... other class code ...
End Class

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by fripper | last post: by
2 posts views Thread by Dave Wurtz | last post: by
8 posts views Thread by Dave Wurtz | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.