我希望开发人员使用类/接口而不是直接导入函数。
有没有办法限制只有类才能导入该函数?
我不想将所有功能放在一个文件中,因为它在大型项目中不可扩展
即我不想使用这种模式:
// myclass.ts
// no exports on the functions
function foo(){ ... }
function bar(){ ... }
export class MyClass {
Foo(){ return foo() }
Bar(){ return bar() }
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的目标:
// foo.ts
export function foo(){ ... }
// I want this to be private but it needs to be exported so the class below can use it
// bar.ts
export function bar() { ... }
// myclass.ts
import { foo } from 'foo';
import { bar …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试制作国际象棋游戏,并试图实现一个界面,但我无法访问界面.
public interface IChessPiece
{
bool CheckMove(int row, int col);
}
public class ChessPiece { ... }
public class Pawn : ChessPiece, IChessPiece
{
public bool CheckMove(int row, int col) { ... }
}
public class ChessPieces { public List<ChessPieces> chessPieces; ... }
Run Code Online (Sandbox Code Playgroud)
我似乎无法访问CheckMove()方法.
board.chessPieces.Find(x => <condition>).CheckMove(row, col);
Run Code Online (Sandbox Code Playgroud)