Wan Razali
dream to be rich business man in technology and properties
| Type | Extends (class) | Implements (interface) |
|---|---|---|
| Have shared data? | ||
| Have shared behavior? | ||
| Enforce contract but still same form |
Type of Inheritance
abstract class Cat{
//shared data
private name: string;
public setName(name: string){
this.name = name;
}
public getName(): string{
return this.name;
}
//shared behavior
public meow(){
console.log("meow")
}
//non shared behavior
//assuming cat fur have so many patterns,
//u unable to put it into params or you can put into params
//but the implementation differ so much for different cat
public abstract fur();
}//class cat
What is Shared data & behavior and enforce contract
abstract class MenuNode{
//share data or shared behavior
private label: string;
private ID: number;
private parentID: number;
public getLabel(): string{
return this.string;
}
//non shared
//non shared must use abstract
//what kind of view to be displayed?
public abstract getView(): MenuComponent;
//call another window?
//immediately do action?
public abstract getAction(): MenuAction;
}class MenuGroup extends MenuNode{
constructor(label){
super(label);
}
public getView(): MenuComponent{
//just display veritcal line and its label
}
}
class DropDownMenuItem extends MenuNode{
public getView(): MenuComponent{
//just display name with drop down capabilities
}
}Simple Data Management
To lower Case
Remove "a"
clamp "x"
Input: Nama saya Tom Jerry
nama saya tom jerry
n m s y tom jeryy
xn m s y tom jeryyx
interface Transformer{
transform(input: string): string;
}
//OR
abstract class Transformer{
abstract public transform(input: string): string;
}
//example use
class TransformToLowerCase implements Transformer{
public transform(input: string): string{
return input.toLowerCase();
}
}By Wan Razali