I am re-designing part of our internal ORM tool, and I want to expose Field (a class that represents a field in the database, like CustomerFirstName) directly to the end-developer.
So that was easy enough to accomplish, however the API got a little ugly because this Field class was previously used internally and is too open. For instance, and this is just one small example: the IsDirty property was not read-only, and that's something end-developers shouldn't be able to tamper with.
I thought about maybe creating two interfaces, IPublicField and IPrivateField, and trying to get the field class to implement both of them. However, continuing with the IsDirty example, I didn't want something like this:
Public ReadOnly Property PrivateIsDirty Implements IPrivateField.IsDirty
...
End Property
Public Property IsDirty Implements IPublicField.IsDirty
...
End Property
...It's just a little ugly, plus you could still cast back to the Field class and get into the non-readonly method. I also didn't want to introduce a seperate setter method because it would be another breaking change that I don't want to think about, and it also would create an inconsistency with other parts of the API.
I ended up renaming the Field class to InnerField, and creating a facade/wrapper style structure around it like this:
Public Class Field
Implements BusinessObjects.IField
Private InnerField As BusinessObjects.IInnerField
Public Sub New(ByVal field As IInnerField)
InnerField = field
End Sub
...
Public ReadOnly Property IsDirty() As Boolean Implements BusinessObjects.IField.IsDirty
Get
Return InnerField.IsDirty
End Get
End Property
...
End Class
This seems to be working out pretty well. Internally, the InnerField is suitably open and we have the freedom to make it more open in the future without impacting end-developers, and externally the Field class provides the simplified, locked down tool that end-developers need.
So, assuming that was coherant, I was wondering how you might have proceeded in this situation, and whether my solution seems reasonable from the outside.
Thanks!