标签: interface

接口dll中的类实现?

我的问题:在应用程序内部,所有接口都在自己的dll中声明(例如,项目"接口").

在项目界面内部,也有许多类实现.

现在我需要在另一个项目中使用这个已实现的类之一并获得环依赖项,因为该项目也是项目接口中的引用.

那么,绕过这种环依赖的最佳方法是什么?这可能是应用程序设计中的一个大错误吗?

示意图:

IBigInterface.cs(一个文件中的所有内容):

interface ISomeInterfaceA
{
    void SomeFunctionA(ClassB x);    // ClassB from newProject.cs
    void SomeFunctionB();
}

//
// etc.
//
class ClassA
{
    //
    // Code
    //
}
Run Code Online (Sandbox Code Playgroud)

newProject.cs(一个文件中的所有内容):

class ClassB
{
    //
    // used in interfaces.dll
    //
}

class ClassC
{
    void SomeFunction(ClassA a)    // ClassA from IBigInterface.cs
    {
        //
        // do something
        //
    }
}
Run Code Online (Sandbox Code Playgroud)

我想到的第一件事就是...... 喜欢:

IBigInterface.cs:

interface ISomeInterfaceA
{
    void SomeFunctionA(IInterfaceB x);    // use interface instead of a class
    void SomeFunctionB();
}

interface …
Run Code Online (Sandbox Code Playgroud)

c# architecture class-design interface

0
推荐指数
1
解决办法
2717
查看次数

接口方法的成员有不同的类型

我有这个界面

public interface TestInterface
{
   [returntype] MethodHere();
}

public class test1 : TestInterface
{
   string MethodHere(){
      return "Bla";
   }
}

public class test2 : TestInterface
{
   int MethodHere(){
     return 2;
   }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让[returntype]动态?

c# types interface member

0
推荐指数
1
解决办法
105
查看次数

获取变量的类级实例(不是接口)

如果我有以下情况

public interface IFace
{
     int NoseSize {get; set;}
}


public class Face: IFace
{
    private int NoseSize;

    public int IFace.NoseSize
    {
        get { return ClassLevel.NoseSize}
        set { ClassLevel.NoseSize = value}
    }
}
Run Code Online (Sandbox Code Playgroud)

我如何真正指出"ClassLevel"?

.net c# interface

0
推荐指数
1
解决办法
153
查看次数

在Java中使用接口作为构造函数参数?

我怎样才能完成以下任务:

public class testClass implements Interface {
     public testClass(Interface[] args) {
     }
}
Run Code Online (Sandbox Code Playgroud)

所以我可以宣布

Interface testObject = new testClass(new class1(4), new class2(5));
Run Code Online (Sandbox Code Playgroud)

class1和class2也是实现Interface的类.

另外,一旦我完成了这个,我怎样才能引用在testClass中使用的每个参数?

谢谢 :)

java parameters constructor design-patterns interface

0
推荐指数
1
解决办法
2532
查看次数

更高级的接口用法

说实话,我不太确定自己是否理解这个任务:)我被告知创建类MySimpleIt,它实现了Iterator和Iterable,并允许运行提供的测试代码.对象的参数和变量不能是集合或数组.
代码 :

 MySimpleIt msi=new MySimple(10,100,
                           MySimpleIt.PRIME_NUMBERS);

 for(int el: msi)
   System.out.print(el+" ");    
 System.out.println();

 msi.setType(MySimpleIterator.ODD_NUMBERS);
 msi.setLimits(15,30);
 for(int el: msi)
   System.out.print(el+" ");    
 System.out.println();

 msi.setType(MySimpleIterator.EVEN_NUMBERS);
 for(int el: msi)
   System.out.print(el+" ");    
 System.out.println();
Run Code Online (Sandbox Code Playgroud)

我应该得到的结果:

11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 


15 17 19 21 23 25 27 29 


16 18 20 22 24 26 28 30
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import java.util.Iterator; 
interface MySimpleIterator{
    static int ODD_NUMBERS=0;
    static int EVEN_NUMBERS = 1;
    static …
Run Code Online (Sandbox Code Playgroud)

java iteration iterator interface

0
推荐指数
1
解决办法
1576
查看次数

显式调用Runnable.run

有人在我之前处理我的代码,创建了一些方法并将Runnable作为参数传递,更有可能:

void myMethod(Runnable runnable){ runnable.run(); }
Run Code Online (Sandbox Code Playgroud)

然后从主要调用myMethod看起来像:

public static void main(String args[]) 
{ try 
{ myMethod(new Runnable(){ public void run() { //do something...; }}); } 
catch (Throwable t) { } }
Run Code Online (Sandbox Code Playgroud)

因此,要向myMethod提供参数,我需要实例化实现Runnable的(在这种情况下是匿名)类的对象.

我的问题是:在这个例子中是否有必要使用Runnable?我可以使用任何不同的界面吗?我的意思是我可以使用单一方法创建新界面,即

interface MyInterface{ void doThis(); }
Run Code Online (Sandbox Code Playgroud)

然后改变myMethod的外观: void myMethod(MyInterface myObject){ myObject.doThis(); }

客户当然也是:

public static void main(String args[]) { 
try { myMethod(new MyInterface (){ public void doThis() 
{ //do something...; }}); } 
catch (Throwable t) { } }
Run Code Online (Sandbox Code Playgroud)

或者也许是关于Runnable的东西?!

java multithreading interface

0
推荐指数
1
解决办法
583
查看次数

如何使用ArrayList使用ICollection存储一些数据

我想使用ArrayList将少量字符串存储到数组中.

如何在不使用Add函数的情况下一次存储所有字符串.无论如何它是否与接口ICollection有些相关.我可以使用ICollection来存储我的数组.如果是的话.

ArrayList _1019=new ArrayList("TEN","ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN");
Run Code Online (Sandbox Code Playgroud)

我想将它存储在C#中的类的构造函数中

.net c# interface arraylist arraycollection

0
推荐指数
1
解决办法
2855
查看次数

Delphi:麻烦调用函数返回接口

我正在尝试调用一个函数从另一个单元返回一个接口; 例如,考虑以下内容:

program intf_sb1;
{$APPTYPE CONSOLE}
uses
  myunit in 'myunit.pas';
var
  MyBL: ISomeInterface;
begin
  MyBL := GetInterface;
end.
Run Code Online (Sandbox Code Playgroud)

其内容myunit.pas如下:

unit myunit;
interface
type
  ISomeInterface = interface
    ['{D25A26ED-7665-4091-9B0F-24DF37545E2A}']
  end;
implementation

function GetInterface : ISomeInterface;
begin
end;

end.
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我尝试运行此程序时,我收到错误"E2003 Undecleared identifier GetInterface".为什么不允许这样做?提前致谢!

delphi interface function

0
推荐指数
1
解决办法
578
查看次数

在CoCreateInstance之前调用QueryInterface?

以上可能吗?

我可以这样做:

IUnknown *punk;

punk->QueryInterface(IID_MyInterface, (void**)&m_pMyInterface);
Run Code Online (Sandbox Code Playgroud)

我以为这会告诉我MyInterface是否支持m_pMyInterface ...

c++ com interface

0
推荐指数
1
解决办法
889
查看次数

Java接口实现问题

我有一点问题.

第ll类:

interface jj{
    public class ll implements gg{
    public static String j ="C:\\";
        //some code here
}
}
Run Code Online (Sandbox Code Playgroud)

班级ggg:

interface gg{
public class ggg extends JFrame implements jj{
               //bunch of code + a textfield
        textField = new JTextField();
        textField.setBounds(72, 120, 217, 20);
        textField.setColumns(10);
               //bunch of code
}
}
Run Code Online (Sandbox Code Playgroud)

CLass aaa

public class aaa implements jj, gg {
    public aaa(){

//File chooser here + editing strin "j" from class "ll"
        File f = chooser.getSelectedFile();



        if(f!=null)
        {
            jj.ll.j = f.getPath(); 
                //And …
Run Code Online (Sandbox Code Playgroud)

java inheritance implementation interface

0
推荐指数
1
解决办法
244
查看次数