-
April 25th, 2006, 01:04 PM
#1
VB.NET/C#: Require Usage of Interfaces
Hi
I am looking for a way to have my developers (C#, VB.NET) to
use classes via interfaces only. I do not want to achieve this
using management processes (development policies), but via
a specific implementation of classes.
I present a way how to do this, however, I am not completely
happy with it.
An example (in VB.NET, because this requirement is more of an issue here):
Code:
Public Interface IClass1
Function IWhoAmI() As String
End Interface
Public Class Class1
Implements IClass1
Protected[ Friend]/Private Function WhoAmI() As String Implements IClass1.IWhoAmI
Return "Class: Class1 "& vbCrLf &" Interface: IClass1"
End Function
End Class
I can use this class/interface as follows:
Code:
' 1. Way:
Dim Test_I As IClass1
Test_I = New Class1
Test_I.IWhoAmI()
' 2.Way:
Dim Test_C As Class1
Test_C = New Class1
Test_C... ' <-- empty, no function available
Thus, using this approach I need the class Class1 Public (or at least
Friend [default]), as well as the New-operator. The nice thing here is,
however, that the Test_C-object does not allow to use any function
(fine, so far).
But I am not happy since this requires that my class Class1 has
no public elements. This is achieved by design, however there are
people coding. Hence, ...
I would like to have a way, which does not allow the "2.Way".
Any help is appreciated.
Cheers
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|