Created
August 19, 2018 14:58
-
-
Save RayLuxembourg/ed2a28788c76f3cc33a1907a49e0fd4d to your computer and use it in GitHub Desktop.
dry-example.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BaseProduct { | |
name: string; | |
id: number; | |
price: number; | |
} | |
interface ProductsList { | |
top: BaseProduct[]; | |
bottom: BaseProduct[]; | |
} | |
class Slider { | |
data: ProductsList | |
next(): void { } | |
prev(): void { } | |
select(): void { } | |
} | |
abstract class AbstractSlider extends Slider { | |
//will handle this.data | |
abstract initData(): void; | |
init() { | |
this.initData(); | |
//... rest of the flow | |
} | |
} | |
class SliderX extends AbstractSlider{ | |
initData() { | |
this.data = this.getStandartProduct(); | |
} | |
getStandartProduct(): ProductsList { | |
return { top: [], bottom: [] } | |
} | |
} | |
class SliderY extends AbstractSlider{ | |
initData() { | |
const baseProduct = this.getBaseProduct(); | |
const bottom = this.getRecommendedProducts(baseProduct.id); | |
this.data = { | |
top: [baseProduct], | |
bottom | |
} | |
} | |
getBaseProduct(): BaseProduct { | |
return { | |
name: 'someName', | |
id: 1, | |
price: 33 | |
} | |
} | |
getRecommendedProducts(baseProductId: number): BaseProduct[] { | |
// get Recommended products from server using the baseProduct | |
return [{ | |
name: 'someName', | |
id: 1, | |
price: 33 | |
}]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment