저는 상대적으로이 글을 읽었으므로 typescript를 사용하여 의존성 삽입을 구현하고 싶습니다. 자바 또는 C#을 OOP 용으로 프로그래밍하면 더 쉽게이 패턴을 적용 할 수 있습니다. 인터넷에서 예제를 찾았 으면 Eclipse 및 Visual Studio에서 문제없이 사용할 수 있지만 typescript에서 IDE를 사용하면 오류가 발생합니다 이 같은 :은 typescript를 사용하여 의존성 삽입을 사용하는 방법입니다.
Supplied parameters do not match any signature of call target
바로이 오류가
을 나타날 때이를 구현의 끝에개내 기본 클래스 : 오류가 표시되는 위치
class Motor {
Acelerar(): void {
}
GetRevoluciones(): number {
let currentRPM: number = 0;
return currentRPM;
}
}
export {Motor};
내 수업 여기에 모터
import { Motor } from "./1";
class Vehiculo {
private m: Motor;
public Vehiculo(motorVehiculo: Motor) {
this.m = motorVehiculo;
}
public GetRevolucionesMotor(): number {
if (this.m != null) {
return this.m.GetRevoluciones();
}
else {
return -1;
}
}
}
export { Vehiculo };
내 인터페이스와 모터
interface IMotor {
Acelerar(): void;
GetRevoluciones(): number;
}
class MotorGasoline implements IMotor {
private DoAdmission() { }
private DoCompression() { }
private DoExplosion() { }
private DoEscape() { }
Acelerar() {
this.DoAdmission();
this.DoCompression();
this.DoExplosion();
this.DoEscape();
}
GetRevoluciones() {
let currentRPM: number = 0;
return currentRPM;
}
}
class MotorDiesel implements IMotor {
Acelerar() {
this.DoAdmission();
this.DoCompression();
this.DoCombustion();
this.DoEscape();
}
GetRevoluciones() {
let currentRPM: number = 0;
return currentRPM;
}
DoAdmission() { }
DoCompression() { }
DoCombustion() { }
DoEscape() { }
}
을의 유형을 사용하고 있습니다 :
import { Vehiculo } from "./2";
enum TypeMotor {
MOTOR_GASOLINE = 0,
MOTOR_DIESEL = 1
}
class VehiculoFactory {
public static VehiculoCreate(tipo: TypeMotor) {
let v: Vehiculo = null;
switch (tipo) {
case TypeMotor.MOTOR_DIESEL:
v = new Vehiculo(new MotorDiesel()); break;
case TypeMotor.MOTOR_GASOLINE:
v = new Vehiculo(new MotorGasoline()); break;
default: break;
}
return v;
}
}
내가 싶어 SIMPLE-DIJS 또는 D4js 또는 잠시 다른 같은 어떤 라이브러리 나 모듈을 사용하지 않는, 그냥 싶어 그들없이 구현하는 방법을 알고
는 내가 그것을 얻을하지 않습니다 자신의 생성자 – Lrawls
입니다 있습니다. 코드 샘플로 질문을 업데이트하고 무엇을하고 싶습니까? –
잊어 버리십시오, 끝났습니다. – Lrawls