What does IT guys mean by “IDEMPOTENCE ”?
Hello and Welcome,
Today Imm’a talk about the term “idempotence”.
Sometimes we worry about re-calling a method again and again while debugging our code and we have our point here because this may cause some problems in our test and even in our data.
What is Method Idempotence?
If you are using a method which is called “idempotence” you don’t have to worry about those we mention on the previous paragraph, because it will always return the same exact resuly and will do the same operations on every call.
Let’s explain this with an example;
public void a(){
i = 50;
}
public void b(){
i = i + 1;
}
Once method “a” is called, the value of variable “i” will be 50. The result will not change when we are called once again.
When the “b” method is called once, the value of the “i” variable will be one more. For example, if the initial value of “i” is 20, the first time we call it, its value will be 21. If we call it once again, the value of “i” will be 22.
In this case, the “a” method is the idempotent method, and the “b” method is the non-idempotent method.
Happy Coding.