Let me back up and see if I understand you correctly.  What you are saying
is that you can implement this in a good or bad way.  Either way it will
work.  But why implement the bad option if you can just as easily implement
the good?  Is that what you are saying?

Let me see if I am following what you are saying in regards to the code.
Below is a good and bad version of the basic FullName Class we've been
playing with.  I have listed it in VB.Net and C# and I have actually
executed to the code and tested to it make sure they both work the same...
and they do.  So what comes in and what comes out is not the issue... right?


Is it just the implementation that is the concern?

Jon


Public Class Good

    Private _FirstName As String = ""
    Private _LastName As String = ""

    Public Property FullName() As String
        Get
            Return _FirstName & Space(_FirstName.Length - 10) & _LastName &
Space(_LastName.Length - 10)
        End Get
        Set(ByVal value As String)
            _FirstName = value.Substring(0, 10)
            _LastName = value.Substring(10, 10)
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property

End Class

Public Class Bad

    Private _Buffer As String = ""

    Public Property FullName() As String
        Get
            Return _Buffer
        End Get
        Set(ByVal value As String)
            _Buffer = value
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return Mid(_Buffer, 1, 10)
        End Get
        Set(ByVal value As String)
            _Buffer = value & Mid(_Buffer, value.Length + 1) & Space(10 -
value.Length)
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return Mid(_Buffer, 11, 10)
        End Get
        Set(ByVal value As String)

            _Buffer = Mid(_Buffer, 1, 10) & value & Space(10 - value.Length)
        End Set
    End Property

End Class


If you rather look at C#, here it is.  I'm not sure if Space() works in C#
to insert a given number of spaces.  If not, then that would have to change.
I did not text the C# version, just converted the VB code to C#.

public class Good
{
 private string _FirstName = "";
 private string _LastName = "";

 public string FullName {
   get {
     return _FirstName + Space(_FirstName.Length - 10) + _LastName +
Space(_LastName.Length - 10);
   }
   set {
     _FirstName = value.Substring(0, 10);
     _LastName = value.Substring(10, 10);
   }
 }

 public string FirstName {
   get {
     return _FirstName;
   }
   set {
     _FirstName = value;
   }
 }

 public string LastName {
   get {
     return _LastName;
   }
   set {
     _LastName = value;
   }
 }
}
public class Bad
{
 private string _Buffer = "";

 public string FullName {
   get {
     return _Buffer;
   }
   set {
     _Buffer = value;
   }
 }

 public string FirstName {
   get {
     return Mid(_Buffer, 1, 10);
   }
   set {
     _Buffer = value + Mid(_Buffer, value.Length + 1) + Space(10 -
value.Length);
   }
 }

 public string LastName {
   get {
     return Mid(_Buffer, 11, 10);
   }
   set {
     _Buffer = Mid(_Buffer, 1, 10) + value + Space(10 - value.Length);
   }
 }
}

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to