This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B encapsulation concept

 
Vad Fogel
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

given the following:


which is true about the classes described above?
A. Class A is tightly encapsulated.
B. Class B is tightly encapsulated.
C. Classes A and B are both tightly encapsulated.
D. Neither class A nor class B is tightly encapsulated.


The answer is obviously D, but my question is regarding the explanation and the concept in general:
At first glance class B appears to be encapsulated...

Well, the principle of encapsulation says that the class should have all of its state private while providing public getters and setters to access and modify the state. There is only a setter in B, so would we still consider it being tightly encapsulated if foo variable in A were declared private?
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if the variable in class A had been declared private then the subclass B would be tightly encapsulated.
Encapsulation requires member variables to be declared private. There is no requirement to add getter and setter methods if they are not needed for your application.
 
Vad Fogel
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan, this really helps clear the concept.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait... something's weird here...
Was that Dan making a post ?? Wow!
Hey Dan! How've ya been?

-Bert
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's me!
I've been fine. I wish I could offer a good excuse for my disappearance, but I can't. There was no alien abduction or anything interesting like that. I can't even claim a hostage situation. Last spring, I went on vacation and just didn't get back into ranching when I returned.
Judging by your posts, it appears that you have been very busy and doing well here at the Ranch.
I'll try not to make a stranger of myself in the future.
It's nice to be back.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic