You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Oleg Kalnichevski <ol...@apache.org> on 2013/06/17 15:03:38 UTC

Re: svn commit: r1493743

On Mon, 2013-06-17 at 12:44 +0000, sebb@apache.org wrote:
> Author: sebb
> Date: Mon Jun 17 12:44:30 2013
> New Revision: 1493743
> 

...

> Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java?rev=1493743&r1=1493742&r2=1493743&view=diff
> ==============================================================================
> --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java (original)
> +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java Mon Jun 17 12:44:30 2013
> @@ -178,7 +178,7 @@ public class LengthDelimitedEncoder exte
>          buffer.append("; pos: ");
>          buffer.append(this.contentLength - this.remaining);
>          buffer.append("; completed: ");
> -        buffer.append(this.completed);
> +        buffer.append(isCompleted());
>          buffer.append("]");
>          return buffer.toString();
>      }
> 
> 

What is the benefit of doing so? Now we have a bizarre situation when
one instance variable is accessed via a getter and two are not.

Oleg 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: svn commit: r1493743

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Jun 17, 2013 at 9:27 AM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Mon, 2013-06-17 at 09:15 -0400, Gary Gregory wrote:
> > On Mon, Jun 17, 2013 at 9:03 AM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
> >
> > > On Mon, 2013-06-17 at 12:44 +0000, sebb@apache.org wrote:
> > > > Author: sebb
> > > > Date: Mon Jun 17 12:44:30 2013
> > > > New Revision: 1493743
> > > >
> > >
> > > ...
> > >
> > > > Modified:
> > >
> httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > > > URL:
> > >
> http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java?rev=1493743&r1=1493742&r2=1493743&view=diff
> > > >
> > >
> ==============================================================================
> > > > ---
> > >
> httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > > (original)
> > > > +++
> > >
> httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > > Mon Jun 17 12:44:30 2013
> > > > @@ -178,7 +178,7 @@ public class LengthDelimitedEncoder exte
> > > >          buffer.append("; pos: ");
> > > >          buffer.append(this.contentLength - this.remaining);
> > > >          buffer.append("; completed: ");
> > > > -        buffer.append(this.completed);
> > > > +        buffer.append(isCompleted());
> > > >          buffer.append("]");
> > > >          return buffer.toString();
> > > >      }
> > > >
> > > >
> > >
> > > What is the benefit of doing so? Now we have a bizarre situation when
> > > one instance variable is accessed via a getter and two are not.
> > >
> >
> > Accessing an ivar breaks encapsulation, which means that a call site has
> > intimate knowledge of the internals of the object. What is worse, is that
> > if an object also has getters and setters, these methods may be doing
> > additional work. At work, all ivars are private unless there is a string
> > case for a subclass needing access.
> >
>
> But this is #toString() of the same class, isn't it?. How on earth does
> this break encapsulation? I am fine with using getters for accessing
> internal variables inside the same class as long as it is consistent.
>

Right, so if you are in the same class, it is OK, but you do not know that
just looking at a diff file for example, so it might raise a flag during
code review. I agree that consistency is important, so it seems simpler to
always use accessors, which can be private if need be.

Gary

>
> Oleg
>
> > Gary
> >
> >
> > >
> > > Oleg
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> > > For additional commands, e-mail: dev-help@hc.apache.org
> > >
> > >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: svn commit: r1493743

Posted by sebb <se...@gmail.com>.
On 17 June 2013 14:27, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Mon, 2013-06-17 at 09:15 -0400, Gary Gregory wrote:
>> On Mon, Jun 17, 2013 at 9:03 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>>
>> > On Mon, 2013-06-17 at 12:44 +0000, sebb@apache.org wrote:
>> > > Author: sebb
>> > > Date: Mon Jun 17 12:44:30 2013
>> > > New Revision: 1493743
>> > >
>> >
>> > ...
>> >
>> > > Modified:
>> > httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
>> > > URL:
>> > http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java?rev=1493743&r1=1493742&r2=1493743&view=diff
>> > >
>> > ==============================================================================
>> > > ---
>> > httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
>> > (original)
>> > > +++
>> > httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
>> > Mon Jun 17 12:44:30 2013
>> > > @@ -178,7 +178,7 @@ public class LengthDelimitedEncoder exte
>> > >          buffer.append("; pos: ");
>> > >          buffer.append(this.contentLength - this.remaining);
>> > >          buffer.append("; completed: ");
>> > > -        buffer.append(this.completed);
>> > > +        buffer.append(isCompleted());
>> > >          buffer.append("]");
>> > >          return buffer.toString();
>> > >      }
>> > >
>> > >
>> >
>> > What is the benefit of doing so? Now we have a bizarre situation when
>> > one instance variable is accessed via a getter and two are not.
>> >
>>
>> Accessing an ivar breaks encapsulation, which means that a call site has
>> intimate knowledge of the internals of the object. What is worse, is that
>> if an object also has getters and setters, these methods may be doing
>> additional work. At work, all ivars are private unless there is a string
>> case for a subclass needing access.
>>
>
> But this is #toString() of the same class, isn't it?.

No, it's not the same class; the completed field is in AbstractContentEncoder.

It looks like using this.completed does not cause a warning/error even
if completed is actually in a super-class

> How on earth does
> this break encapsulation? I am fine with using getters for accessing
> internal variables inside the same class as long as it is consistent.

> Oleg
>
>> Gary
>>
>>
>> >
>> > Oleg
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> > For additional commands, e-mail: dev-help@hc.apache.org
>> >
>> >
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: svn commit: r1493743

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2013-06-17 at 09:15 -0400, Gary Gregory wrote:
> On Mon, Jun 17, 2013 at 9:03 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > On Mon, 2013-06-17 at 12:44 +0000, sebb@apache.org wrote:
> > > Author: sebb
> > > Date: Mon Jun 17 12:44:30 2013
> > > New Revision: 1493743
> > >
> >
> > ...
> >
> > > Modified:
> > httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > > URL:
> > http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java?rev=1493743&r1=1493742&r2=1493743&view=diff
> > >
> > ==============================================================================
> > > ---
> > httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > (original)
> > > +++
> > httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > Mon Jun 17 12:44:30 2013
> > > @@ -178,7 +178,7 @@ public class LengthDelimitedEncoder exte
> > >          buffer.append("; pos: ");
> > >          buffer.append(this.contentLength - this.remaining);
> > >          buffer.append("; completed: ");
> > > -        buffer.append(this.completed);
> > > +        buffer.append(isCompleted());
> > >          buffer.append("]");
> > >          return buffer.toString();
> > >      }
> > >
> > >
> >
> > What is the benefit of doing so? Now we have a bizarre situation when
> > one instance variable is accessed via a getter and two are not.
> >
> 
> Accessing an ivar breaks encapsulation, which means that a call site has
> intimate knowledge of the internals of the object. What is worse, is that
> if an object also has getters and setters, these methods may be doing
> additional work. At work, all ivars are private unless there is a string
> case for a subclass needing access.
> 

But this is #toString() of the same class, isn't it?. How on earth does
this break encapsulation? I am fine with using getters for accessing
internal variables inside the same class as long as it is consistent.

Oleg

> Gary
> 
> 
> >
> > Oleg
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> > For additional commands, e-mail: dev-help@hc.apache.org
> >
> >
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: svn commit: r1493743

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Jun 17, 2013 at 9:03 AM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Mon, 2013-06-17 at 12:44 +0000, sebb@apache.org wrote:
> > Author: sebb
> > Date: Mon Jun 17 12:44:30 2013
> > New Revision: 1493743
> >
>
> ...
>
> > Modified:
> httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> > URL:
> http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java?rev=1493743&r1=1493742&r2=1493743&view=diff
> >
> ==============================================================================
> > ---
> httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> (original)
> > +++
> httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedEncoder.java
> Mon Jun 17 12:44:30 2013
> > @@ -178,7 +178,7 @@ public class LengthDelimitedEncoder exte
> >          buffer.append("; pos: ");
> >          buffer.append(this.contentLength - this.remaining);
> >          buffer.append("; completed: ");
> > -        buffer.append(this.completed);
> > +        buffer.append(isCompleted());
> >          buffer.append("]");
> >          return buffer.toString();
> >      }
> >
> >
>
> What is the benefit of doing so? Now we have a bizarre situation when
> one instance variable is accessed via a getter and two are not.
>

Accessing an ivar breaks encapsulation, which means that a call site has
intimate knowledge of the internals of the object. What is worse, is that
if an object also has getters and setters, these methods may be doing
additional work. At work, all ivars are private unless there is a string
case for a subclass needing access.

Gary


>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory