Looking for some assistance from the angular2 / typescript experts out there to guide me in the right direction before I lose my mind :-)
Here's what I'm trying to achieve:
- I want to create a parent class that implements its own defined parent Interface, using Generic Types so that when creating a child class, I can provide it with the specific and tailored class & data Interface.
- The child class should be able to extend the parent data class by
- Overriding default/parent set variables
- Overwriting parent functions() and having the child's version called instead of the parent's default
In the sample pseudo code below, I expect the call to the child's (inherited) someOtherfunction()
to return "2"...
Is this too much to ask for? I've been searching online but couldn't find any good examples...
Any guidance on how to accomplish this would be greatly appreciated!
Thank you, Oliver
(NOTE: THE CODE BELOW IS FOR DEMONSTRATION PURPOSES AND MIGHT NOT BE FUNCTIONAL)
//
// Parent Class
//
export interface ICoreData <T> {
observeItems: Observable<T[]>;
items: Array<T>;
}
@Injectable()
export class CoreData<T> implements ICoreData<T> {
public observeItems: Observable<T[]>;
private items: Array<T>;
constructor( 'Dependency Injection...' ) {}
coreFunction(): number {
return 1;
}
someOtherfunction(){
return this.coreFunction();
}
}
//
// Child class
//
export interface IMyDataStructure {
name: string;
age: string;
}
export interface ISpecificData extends ICoreData<IMyDataStructure> {
someExtraKey: number;
}
@Injectable()
export class SpecificData extends CoreData<IMyDataStructure> implements ISpecificData {
constructor() {
super();
}
coreFunction(): number{
//
// This function should "override" the parent's original function
// and be called by the parent's someOtherfunction() function
//
return 2;
}
}