如何用接口作为参数测试静态函数?
我已经看到了一个代码,但是我不知道如何设置ipoint2d start
和ipoint2d end
哪个是getangle方法的参数?
public interface IPoint2D
{
int mX { get; set; }
int mY { get; set; }
void Set(int X, int Y);
string ToString();
}
public static class GeometryAlgorithm
{
public static double GetAngle(IPoint2D Start, IPoint2D End)
{
return Math.Atan((End.mY - Start.mY)/(End.mX - Start.mX)) / Math.PI * 180.0f;
}
}
I have seen a code, but I don't know how to set the IPoint2D Start
and IPoint2D End
which are the GetAngle method's parameters?
public interface IPoint2D
{
int mX { get; set; }
int mY { get; set; }
void Set(int X, int Y);
string ToString();
}
public static class GeometryAlgorithm
{
public static double GetAngle(IPoint2D Start, IPoint2D End)
{
return Math.Atan((End.mY - Start.mY)/(End.mX - Start.mX)) / Math.PI * 180.0f;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该定义实现此接口的类。现在是演示代码
,您可以创建此类的实例,并将其传递给
getangle
方法。First, you should define a class implementing this interface. Here is demo code
Now you can create instances of this class and pass it to
GetAngle
method.接口表示对象之间的合同。如果要测试接口,则需要创建一个实现接口的对象。
如果将
ipoint2d
更改为point2d
:那么您可以这样使用它,只要您还更新静态函数以将类型
point> Point2d :
如果您希望将其保留为接口,则必须在类似的类中实现它:
Interfaces represent a contract between objects. If you want to test your interface you need to create an object that implements the interface.
If you change your
IPoint2D
toPoint2D
:Then you could use it like so, as long as you also update your static function to take objects of type
Point2D
:If you wish to keep it as an interface, you'll have to have it implemented in a class like so: