All Questions
7 questions
0
votes
4
answers
375
views
methods that has only behavior and not manage class state, is that violation of encapsulation
This is a simple scenario in an office with employees and their manager.
In this scenario, both managers and employees have a name attribute.
Only the manager can change his own name
Only the ...
4
votes
6
answers
2k
views
The ID of an object is null at start. Does that make the object state invalid and violate encapsulation?
This question is related to How should an `Employee` class be designed?
In the above question, to uniquely identify an employee, each Employee object has an id field as shown below
class Employee
{
...
3
votes
2
answers
4k
views
How is encapsulation broken by getters/setters, even when using MVC model [duplicate]
I was thinking about encapsulation in Java and then I thought how getters/setters break encapsulation. After I went through this , I saw many recommendations like to avoid getters/setters on fields ...
3
votes
3
answers
548
views
'Encapsulation Vs Performance' trade-off in a lockable linked list
Main purpose of encapsulation is to protect in-variants of any class(in java).
Here is the complete code for class DList/class lockDList/class DListNode/class LockDListNode.
class DList and it's ...
0
votes
1
answer
7k
views
Access fields of super class from derived classes [duplicate]
There is an abstract BaseGame class that will be inherited by specific game classes.
This class has an attribute requestHandler that will be used in all subclasses and should be initialized in the ...
1
vote
2
answers
341
views
Query on hiding implementation details in java
With the below piece of thread related code, I see that author of Thread class is hiding the details about the working of start() method. What a user of Thread class need to know is, class Thread ...
2
votes
1
answer
1k
views
Should we encapsulate everything in a try{} block in a Try object?
Why can't I make a class for a Try including what I try and then run that in the try {} block? Why is it impractical?
class DBConnectTry extends Try {
TryResponse response[] attempt(TryObject o[...