I know that interface are just contracts and they do not provide implementations.For example when i have
interface ISomething {
exportJson():boolean;
}
export class AppComponent implements ISomething {
}
to implement the interface i will do the following
export class AppComponent implements ISomething {
exportJson(): boolean {
throw new Error('Method not implemented.');
}
}
when i implement this interface i want specific logic inside - automatically for example
exportJson(): boolean {
let getJsonPath = '';
// some oher IMPLEMENTATION LOGIC
return true;
}
if i try with classes
class Something {
exportJson() {
let getJsonPath = '';
// some oher IMPLEMENTATION LOGIC
return true;
}
}
export class AppComponent extends Something {
}
then i will have the implementation of the exportJson but there is not contract between, by cotnract i mean that the exportJson method must be implemented - we get error when we are not implementing some method from the interface.
Is there way for this ?