Property... why?

  • Thread starter Thread starter djake
  • Start date Start date
Obviously, JD1 is more encapsulated! Look at the code below. I can do this
change within the class and the logic in Main does not change at all! If I
need to do this with JD2, then I have to change the code in the class *and*
the code in Main. This is a perfect example of encapsulation in a class.

<CODE>
Private myvalue1a As String
Private myvalue1b As String
Friend Property JD1() As String
Get
Return myvalue1a + myvalue1b
End Get
Set(ByVal Value As String)
Dim SA() as String = Value.Split(":")
myvalue1a = SA(0)
myvalue1b = SA(1)
End Set
End Property
</CODE>
 
JD,

Although your code is very bad; It uses a + as concatinationoperator while
that should be a & for strings and it uses a ":" as a seperator for a string
split without any checking. Have I told that when it was good done in this
thread that that is one of the reasons to use properties. Please tell it why
it should with the sample I gave.

Cor
 
No kidding it was bad code, it was just an example.

I *have* shown why you should use properties and either you are not reading
my
messages or you don't understand.

The *why* is encapsulation. Encapsulation is the ability to change the
underlying implementation of the class without the change effecting the
users of the class. Basically its the public interface of the class versus
the implementation of the class. The fact that a change happens or not is
irrelevant, having the ability is the *why* you keep asking about.

In your example JD1 has the ability to change without effecting clients of
the class. I *have* shown this. JD2 does not have the ability, if it
changes, then clients have to change also.

I have again shown my point and again shown why to use properties. All of
this is basic OOP 101. If you don't understand then I suggest you do some
reading on OOP.

If you disagree with this message, then you tell me *why* the use of
encapsulation is wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top