Hello, Laurent_R. You are right. The author of the book did not explicitly write about the inherent dangers of using accessors. Nor did I claim that he did. I was merely speaking from my viewpoint that ensued after reading chapter 9. It was merely my own abstraction. It was more personal than universal. I apologize for not being able to communicate clearly. I am new to OOP. The moment I saw $self->{'attribute'} = shift; being used in the setter and $self->{'attribute'} in the getter functions, it gave me the notion that the encapsulation was being broken. But I may be wrong. My understanding is that the object's innards should stay inside the object. That's my understanding of what Randal wrote in his book. Then again I may be wrong. I was hoping to find clarity as to whether it is perfectly legal to access the object's data directly inside the setter/getter function. While I understand that it is not advised that an API caller use $object->{'attribute'} to access or update the object's attribute outside a class, I don't understand why it seems perfectly alright for the setter and getter methods to use $self->{'attribute'} for changing and accessing attributes internally? Why? This is what Randal did not explain in this particular chapter. Does the concept of encapsulation apply to the code found in the setter and getter functions? If it is so, isn't $self->{'attribute'} = shift; a violation of the encapsulation? Or is this a privilege that setter and getter functions have over API callers?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|