Answer the question
In order to leave comments, you need to log in
How to create an interface that would implement its constructor in an object?
How do I use an interface to implement a constructor in an object?
For example, I have an object whose methods all use the user ID:
public interface ILogic
{
void Add(int userId);
void Change(int userId);
}
public class logic: ILogic
{
public void add(int userId)
{
....
}
public void change (int userId)
{
....
}
}
public class logic
{
private int _userId;
public logic(int userId)
{
_userId = userId
}
public void add()
{
// ... делаем что либо используя _userId
}
public void change()
{
// ... делаем что либо используя _userId
}
}
Answer the question
In order to leave comments, you need to log in
An interface is simply a class promise that it has "methods like this" with "like this signature". What is your problem? In theory:
public interface ILogic
{
void Add();
void Change();
}
public class someClass
{
private int _someParametr;
private someClass(){}
public static SomeClass CreateInstance(int inputParam)
{
var t = new SomeClass(){_someParametr = inputParam};
return t;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question