Reputation:
I have the following class and interface for him:
public class A // int wrapper
{
private int _a;
public A(int a)
{
_a = a;
}
}
interface IProgram
{
int a();
A b();
}
public class Program : IProgram
{
public int a()
{
int b = 0;
b++;
return b;
}
public A b()
{
int b = 0;
b++;
return new A(b);
}
}
Two methods do the same thing: just increase b
.
How can I avoid code duplication and change my interface?
Upvotes: 0
Views: 145
Reputation: 711
Create a private method which iterates int b and returns it, then call that method from a() and b()
Upvotes: 1