Skip to main content
deleted 73 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36

The second approach is immutable but actually shifts the responsibility of updatingtracking the remaining part outside of the class. The first approach is mutable (am i correct? because its internal state (the remaining part is mutable), but it encapsulates the logic and just need a call to DrawTextInBox to draw the remaining part.

The second approach is immutable but actually shifts the responsibility of updating the remaining part outside of the class. The first approach is mutable (am i correct? because its internal state (the remaining part is mutable) but it encapsulates the logic and just need a call to DrawTextInBox to draw the remaining part.

The second approach is immutable but actually shifts the responsibility of tracking the remaining part outside of the class. The first approach is mutable, but it encapsulates the logic and just need a call to DrawTextInBox to draw the remaining part.

deleted 9 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
class Mutable { private int i; public Mutable(int _i) { i = _i} public void Print() // impure function { print(i); i++; // logic inside } } ... caller int i =1; Immutable m = new Mutable(i1); while (true) { m.Print(); } 
class Mutable { private int i; public Mutable(int _i) { i = _i} public void Print() // impure function { print(i); i++; // logic inside } } ... caller int i =1; Immutable m = new Mutable(i); while (true) { m.Print(); } 
class Mutable { private int i; public Mutable(int _i) { i = _i} public void Print() // impure function { print(i); i++; // logic inside } } ... caller Immutable m = new Mutable(1); while (true) { m.Print(); } 
added 8 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36

Question: The logic of the above examples was simple but this logic could be more complex, then I don't know whether to extract this logic from a class in order to make it immutable or let it be mutable and have the logic inside?

Question: The logic of the above examples was simple but this logic could be more complex, then I don't know to extract this logic from a class in order to make it immutable or let it be mutable and have the logic inside?

Question: The logic of the above examples was simple but this logic could be more complex, then I don't know whether to extract this logic from a class in order to make it immutable or let it be mutable and have the logic inside?

added 126 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
edited title
Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
added 57 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
added 868 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
added 868 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
added 25 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
Tweeted twitter.com/#!/StackProgrammer/status/587991060326014976
added 130 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
added 4 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
added 327 characters in body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
edited body
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading
Source Link
Ahmad
  • 1.9k
  • 3
  • 21
  • 36
Loading